GO语言开发GUI安全工具实践(二)

简介: GO语言开发GUI安全工具实践

对于GUI工具的理解:


首先要有一个模板

对比命令行下的工具,图形化的工具要有事件响应(比如邮件列出菜单)


import tkinter as tk
from tkinter.filedialog import *
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class App(Frame):
def __init__(self,master=None):
super(App, self).__init__()
super().__init__(master)
self.master=master
self.var = tk.StringVar()
self.zapi = "oI5pPuvuGPF5CSSRzCzk4WB8rvIYUkmM"
self.initUI()
self.textpad=None
self.Create()
self.pack()
def Create(self):
menubar=Menu(root)
menuFile=Menu(menubar)
menubar.add_cascade(label="options",menu=menuFile)
menuFile.add_command(label="shellcode",accelerator="ctrl+a",command=self.test)
menubar.add_cascade(label="test",menu=menuFile)
menuFile.add_command()
menuFile.add_command(label="open",accelerator="ctrl+b",command=self.fileopen)
menuFile.add_command(label="save",accelerator="ctrl+c",command=self.filesave)
menuFile.add_command(label="new",accelerator="ctrl+d",command=self.filenew)
root["menu"]=menubar
self.textpad=Text(root,width=200,height=10)
self.textpad.pack()
self.contextMenu=Menu(root)
//右键事件
self.contextMenu.add_command(label="一键装逼",command=self.zha)
self.contextMenu.add_command(label="bg",command=self.openAskColor)
root.bind("<Button-3>",self.createCon)
def zha(self):
pass
def openAskColor(self):
pass
def fileopen(self):
pass
def filesave(self):
pass
def filenew(self):
pass
def createCon(self,event):
self.contextMenu.post(event.x_root,event.y_root)
def test(self):
pass
def initUI(self):
group_top = tk.LabelFrame(self, padx=15, pady=10)
group_top.pack(padx=10, pady=5)
tk.Button(group_top, text="scanIP", width=10, command=self.scanIP).grid(row=0, column=1)
self.path_entry = tk.Entry(group_top, width=30)
self.path_entry.grid(row=0, column=0, pady=5, padx=5)
//添加按钮
tk.Button(group_top, text="开始执行", width=10, command=self.func).grid(row=1, column=1, sticky=tk.E)
tk.Button(group_top, text="停止", width=10, command=self.destroy).grid(row=1, column=0, sticky=tk.W)
console_frame = tk.Frame(group_top).grid(row=2, column=0, columnspan=2)
self.console_text = tk.Text(
console_frame, fg="green", bg="black", width=40, height=20, state=tk.DISABLED)
scrollbar = tk.Scrollbar(console_frame, command=self.console_text.yview)
self.console_text.pack(expand=1, fill=tk.BOTH)
self.console_text['yscrollcommand'] = scrollbar.set
def output_to_console(self, new_text):
self.console_text.config(state=tk.NORMAL)
self.console_text.insert(tk.END, new_text)
self.console_text.see(tk.END)
self.console_text.config(state=tk.DISABLED)
def func(self):
pass
def usage(self):
A = """
__   .__    .___  .___      .__
____________ |  | _|__| __| _/__| _/____  |__|
/  ___/\____ \|  |/ /  |/ __ |/ __ |\__  \ |  |
\___ \ |  |_> >    <|  / /_/ / /_/ | / __ \|  |
/____  >|   __/|__|_ \__\____ \____ |(____  /__|
\/ |__|        \/       \/    \/     \/
"""
B = """
***          by YanMu                            ***
"""
self.output_to_console(f"{A}\n");self.output_to_console(f"{B}\n")
def scanIP(self):
pass
if __name__ == '__main__':
root=Tk()
root.title("Pythonstudy by 雷石安全")
root.geometry("1200x500+200+300")
app = App(master=root)
root.resizable(height=False)
app.usage()
app.mainloop()

代码中pass地方可以写你相应的功能点


demo演示:


449500f1d0c7461be22b6ef94958f6ba_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


然后我们可以在正常的函数除填写我们相应的功能


import tkinter as tk
import shodan
from tkinter.colorchooser import *
from tkinter.filedialog import *
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class App(Frame):
def __init__(self,master=None):
super(App, self).__init__()
super().__init__(master)
self.master=master
self.var = tk.StringVar()
self.zapi = ""//你的api
self.initUI()
self.textpad=None
self.Create()
self.pack()
def Create(self):
menubar=Menu(root)
menuFile=Menu(menubar)
menubar.add_cascade(label="options",menu=menuFile)
menuFile.add_command(label="shellcode",accelerator="ctrl+a",command=self.test)
menubar.add_cascade(label="test",menu=menuFile)
menuFile.add_command()
menuFile.add_command(label="open",accelerator="ctrl+b",command=self.fileopen)
menuFile.add_command(label="save",accelerator="ctrl+c",command=self.filesave)
menuFile.add_command(label="new",accelerator="ctrl+d",command=self.filenew)
root["menu"]=menubar
self.textpad=Text(root,width=200,height=10)
self.textpad.pack()
self.contextMenu=Menu(root)
self.contextMenu.add_command(label="一键装逼",command=self.zha)
self.contextMenu.add_command(label="bg",command=self.openAskColor)
root.bind("<Button-3>",self.createCon)
def zha(self):
pass
def openAskColor(self):
s=askcolor(color="red",title="bg")
self.textpad.config(bg=s[1])
def fileopen(self):
self.textpad.delete("1.0","end")
with askopenfile(title="txt") as f:
self.textpad.insert(INSERT,f.read())
self.filename=f.name
def filesave(self):
with open(self.filename,"w") as f:
c=self.textpad.get(1.0,END)
f.write(c)
def filenew(self):
self.filename=asksaveasfile("另存为",initialfile="log.txt",filetypes=[("文本文档","*.txt")],defaultextension=".txt")
self.filesave()
def createCon(self,event):
self.contextMenu.post(event.x_root,event.y_root)
def test(self):
pass
def initUI(self):
group_top = tk.LabelFrame(self, padx=15, pady=10)
group_top.pack(padx=10, pady=5)
tk.Button(group_top, text="scanIP", width=10, command=self.scanIP).grid(row=0, column=1)
self.path_entry = tk.Entry(group_top, width=30)
self.path_entry.grid(row=0, column=0, pady=5, padx=5)
tk.Button(group_top, text="开始执行", width=10, command=self.func).grid(row=1, column=1, sticky=tk.E)
tk.Button(group_top, text="停止", width=10, command=self.destroy).grid(row=1, column=0, sticky=tk.W)
console_frame = tk.Frame(group_top).grid(row=2, column=0, columnspan=2)
self.console_text = tk.Text(
console_frame, fg="green", bg="black", width=40, height=20, state=tk.DISABLED)
scrollbar = tk.Scrollbar(console_frame, command=self.console_text.yview)
self.console_text.pack(expand=1, fill=tk.BOTH)
self.console_text['yscrollcommand'] = scrollbar.set
def output_to_console(self, new_text):
self.console_text.config(state=tk.NORMAL)
self.console_text.insert(tk.END, new_text)
self.console_text.see(tk.END)
self.console_text.config(state=tk.DISABLED)
def func(self):
se = ""//要搜索的设备
api = shodan.Shodan(self.zapi)
res = api.search(se)
# a=str(result['ip_str'])
for result in res['matches']:
url = str(result['ip_str']) + ":" + str(result['port']) + ":" + str(
result['location']['country_name']) + ":" + str(result['domains'])
# print(url)
self.output_to_console(f"{url}\n")
def usage(self):
A = """
__   .__    .___  .___      .__
____________ |  | _|__| __| _/__| _/____  |__|
/  ___/\____ \|  |/ /  |/ __ |/ __ |\__  \ |  |
\___ \ |  |_> >    <|  / /_/ / /_/ | / __ \|  |
/____  >|   __/|__|_ \__\____ \____ |(____  /__|
\/ |__|        \/       \/    \/     \/
"""
B = """
***          by YanMu                            ***
"""
self.output_to_console(f"{A}\n");self.output_to_console(f"{B}\n")
def scanIP(self):
pa = self.path_entry.get()
scapi = shodan.Shodan(self.zapi)
hosts = scapi.host(pa)
er = str(hosts['ip_str']) + ":" + str(hosts.get('org', 'n/a')) + ":" + str(hosts.get('os', 'n/a'))
self.output_to_console(f"{er}\n")
for host in hosts['data']:
sas = str(host['port']) + ":" + str(host['data'])
self.output_to_console(f"{sas}\n")
if __name__ == '__main__':
root=Tk()
root.title("Pythonstudy by 雷石安全")
root.geometry("1200x500+200+300")
app = App(master=root)
root.resizable(height=False)
app.usage()
app.mainloop()

162063bc781c0e8a14629e4745e14638_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


这里我们填写shodan的搜索为例,当然当时练习的时候尝试写一个记事本的功能来着


GUI个人思路:


有一个样式框架,往里面填东西就行。

你可以把别人命令行式的代码,剪吧剪吧放到自己的工具里面(缺陷:这个demo不能及时反映响应信息)


最后介绍一下,B/S架构思考:


这里我用的tornado框架

还是先有一个模板

import tornado.web
import os
import shodan
import tornado.ioloop
import tornado.httpserver
from tornado.options import define,options,parse_command_line
define("port",default=8888,help="运行端口",type=int)
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render("index.html")
def write_error(self, status_code, **kwargs):
self.write("your caused a %d error."%status_code)
class CoupletHandler(tornado.web.RequestHandler):
def post(self):
first=self.get_argument("first")
second=self.get_argument("second")
self.render("couplet.html",first=sumurls,second=second)
if __name__ == '__main__':
parse_command_line()
print("""
logo:leishi
by caibi-yanmu
""")
print("http://localhost:{}/".format(options.port))
base_dir=os.path.dirname(__file__)
app=tornado.web.Application(
handlers=[
(r"/",IndexHandler),
(r"/couplet",CoupletHandler)
],
template_path=os.path.join(os.path.dirname(os.path.abspath(__file__)),'templates'),
static_path=os.path.join(os.path.dirname(os.path.abspath(__file__)),'static'),
)
http_server=tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()

d38eb3aad9997aeb68abf3b7e1bc8471_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


然后我们向这个demo里面加我们的功能点,这里主要方便测试(外表不重要,嘤嘤嘤)


5dcb6050cab2ef4a6ff674374ce2d6bb_640_wx_fmt=jpeg&wxfrom=5&wx_lazy=1&wx_co=1.jpg



import tornado.web
import os
import shodan
import tornado.ioloop
import tornado.httpserver
from tornado.options import define,options,parse_command_line
define("port",default=8888,help="运行端口",type=int)
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render("index.html")
def write_error(self, status_code, **kwargs):
self.write("your caused a %d error."%status_code)
class CoupletHandler(tornado.web.RequestHandler):
def post(self):
first=self.get_argument("first")
second=self.get_argument("second")
api=shodan.Shodan(first)
sumurls=""
try:
results=api.search(second)
for i in results['matches']:
url=i['ip_str']+":"+str(i['port'])
sumurls+=url+"\n"
except shodan.APIError as e:
print(e)
self.render("couplet.html",first=sumurls,second=second)
if __name__ == '__main__':
parse_command_line()
print("""
logo:leishi
by caibi-yanmu
""")
print("http://localhost:{}/".format(options.port))
base_dir=os.path.dirname(__file__)
app=tornado.web.Application(
handlers=[
(r"/",IndexHandler),
(r"/couplet",CoupletHandler)
],
template_path=os.path.join(os.path.dirname(os.path.abspath(__file__)),'templates'),
static_path=os.path.join(os.path.dirname(os.path.abspath(__file__)),'static'),
)
http_server=tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()

这里师傅们可以根据自己的前端代码去填充对应结果


d62bd901a9f33ae96c4dc52da41adfef_640_wx_fmt=png&wxfrom=5&wx_lazy=1&wx_co=1.png


总结:


我们平常写的命令行下的工具无论是在GUI形式下还是B/S形式下,最后核心的功能点不变,所以说,要是我们平常在测试的过程中,完全可以只写在命令行模式下的小工具。


相关文章
|
4天前
|
消息中间件 Go API
基于Go语言的微服务架构实践
随着云计算和容器化技术的兴起,微服务架构成为了现代软件开发的主流趋势。Go语言,以其高效的性能、简洁的语法和强大的并发处理能力,成为了构建微服务应用的理想选择。本文将探讨基于Go语言的微服务架构实践,包括微服务的设计原则、服务间的通信机制、以及Go语言在微服务架构中的优势和应用案例。
|
4天前
|
Kubernetes Cloud Native Go
Golang深入浅出之-Go语言中的云原生开发:Kubernetes与Docker
【5月更文挑战第5天】本文探讨了Go语言在云原生开发中的应用,特别是在Kubernetes和Docker中的使用。Docker利用Go语言的性能和跨平台能力编写Dockerfile和构建镜像。Kubernetes,主要由Go语言编写,提供了方便的客户端库与集群交互。文章列举了Dockerfile编写、Kubernetes资源定义和服务发现的常见问题及解决方案,并给出了Go语言构建Docker镜像和与Kubernetes交互的代码示例。通过掌握这些技巧,开发者能更高效地进行云原生应用开发。
58 1
|
4天前
|
消息中间件 Go API
Golang深入浅出之-Go语言中的微服务架构设计与实践
【5月更文挑战第4天】本文探讨了Go语言在微服务架构中的应用,强调了单一职责、标准化API、服务自治和容错设计等原则。同时,指出了过度拆分、服务通信复杂性、数据一致性和部署复杂性等常见问题,并提出了DDD拆分、使用成熟框架、事件驱动和配置管理与CI/CD的解决方案。文中还提供了使用Gin构建HTTP服务和gRPC进行服务间通信的示例。
29 0
|
4天前
|
安全 Go
Golang深入浅出之-Go语言中的并发安全队列:实现与应用
【5月更文挑战第3天】本文探讨了Go语言中的并发安全队列,它是构建高性能并发系统的基础。文章介绍了两种实现方法:1) 使用`sync.Mutex`保护的简单队列,通过加锁解锁确保数据一致性;2) 使用通道(Channel)实现无锁队列,天生并发安全。同时,文中列举了并发编程中常见的死锁、数据竞争和通道阻塞问题,并给出了避免这些问题的策略,如明确锁边界、使用带缓冲通道、优雅处理关闭以及利用Go标准库。
26 5
|
4天前
|
存储 缓存 安全
Golang深入浅出之-Go语言中的并发安全容器:sync.Map与sync.Pool
Go语言中的`sync.Map`和`sync.Pool`是并发安全的容器。`sync.Map`提供并发安全的键值对存储,适合快速读取和少写入的情况。注意不要直接遍历Map,应使用`Range`方法。`sync.Pool`是对象池,用于缓存可重用对象,减少内存分配。使用时需注意对象生命周期管理和容量控制。在多goroutine环境下,这两个容器能提高性能和稳定性,但需根据场景谨慎使用,避免不当操作导致的问题。
35 4
|
4天前
|
安全 Java Go
【Go语言专栏】Go语言中的加密与安全通信
【4月更文挑战第30天】本文介绍了Go语言中的加密与安全通信。通过使用golang.org/x/crypto/ssh/terminal库实现终端加密,以及golang.org/x/net/websocket库实现WebSocket安全通信。文章展示了安装库的命令、加密操作及WebSocket通信的示例代码。此外,还列举了安全通信在数据传输加密、用户认证、密码保护和文件加密等场景的应用。掌握这些知识对开发安全的Web应用至关重要。
|
4天前
|
存储 缓存 监控
【Go语言专栏】Go语言应用的性能调优实践
【4月更文挑战第30天】本文介绍了Go语言应用的性能调优技巧,包括使用`pprof`进行性能分析、选择正确算法与数据结构、减少内存分配、优化并发及避免阻塞操作、选用合适锁机制。此外,文章还提到了编译选项如`-trimpath`和`-ldflags`,以及系统资源和环境调优。通过实例展示了代码优化、并发处理和锁的使用。最后,推荐了进一步学习资源,鼓励读者深入探索Go语言的性能优化。
|
4天前
|
存储 关系型数据库 Go
【Go语言专栏】基于Go语言的RESTful API开发
【4月更文挑战第30天】本文介绍了使用Go语言开发RESTful API的方法,涵盖了路由、请求处理、数据存储和测试关键点。RESTful API基于HTTP协议,无状态且使用标准方法表示操作。在Go中,通过第三方库如`gorilla/mux`进行路由映射,使用`net/http`处理请求,与数据库交互可选ORM库`gorm`,测试则依赖于Go内置的`testing`框架。Go的简洁性和并发性使得它成为构建高效API的理想选择。
|
4天前
|
前端开发 Java Go
开发语言详解(python、java、Go(Golong)。。。。)
开发语言详解(python、java、Go(Golong)。。。。)
|
4天前
|
Java Go C#
开发语言漫谈-go
go的设计思路和python差不多,就是要降低入门难度,提高开发效率