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形式下,最后核心的功能点不变,所以说,要是我们平常在测试的过程中,完全可以只写在命令行模式下的小工具。


相关文章
|
消息中间件 缓存 NoSQL
Redis各类数据结构详细介绍及其在Go语言Gin框架下实践应用
这只是利用Go语言和Gin框架与Redis交互最基础部分展示;根据具体业务需求可能需要更复杂查询、事务处理或订阅发布功能实现更多高级特性应用场景。
586 86
|
11月前
|
存储 安全 Java
【Golang】(4)Go里面的指针如何?函数与方法怎么不一样?带你了解Go不同于其他高级语言的语法
结构体可以存储一组不同类型的数据,是一种符合类型。Go抛弃了类与继承,同时也抛弃了构造方法,刻意弱化了面向对象的功能,Go并非是一个传统OOP的语言,但是Go依旧有着OOP的影子,通过结构体和方法也可以模拟出一个类。
508 2
|
Cloud Native 安全 Java
Go:为云原生而生的高效语言
Go:为云原生而生的高效语言
768 1
|
设计模式 人工智能 Go
go 依赖注入实践
依赖注入(DI)是一种软件设计模式,旨在降低代码耦合度,提高代码可测试性和可复用性。其核心思想是将依赖项从外部传入使用对象,而非由其内部创建。通过 DI,模块间关系更清晰,便于维护和扩展。常见实现包括方法注入和接口注入,适用于如 Go 等支持函数式编程和接口抽象的语言。
322 8
|
分布式计算 算法 安全
Go语言泛型-泛型约束与实践
Go语言中的泛型约束用于限制类型参数的范围,提升类型安全性。通过接口定义约束,可实现对数值类型、排序与比较等操作的支持。开发者既可使用标准库提供的预定义约束,如constraints.Ordered和constraints.Comparable,也可自定义约束以满足特定需求。泛型广泛应用于通用数据结构(如栈、队列)、算法实现(如排序、查找)及构建高效可复用的工具库,使代码更简洁灵活。
|
开发框架 JSON 中间件
Go语言Web开发框架实践:路由、中间件、参数校验
Gin框架以其极简风格、强大路由管理、灵活中间件机制及参数绑定校验系统著称。本文详解其核心功能:1) 路由管理,支持分组与路径参数;2) 中间件机制,实现全局与局部控制;3) 参数绑定,涵盖多种来源;4) 结构体绑定与字段校验,确保数据合法性;5) 自定义校验器扩展功能;6) 统一错误处理提升用户体验。Gin以清晰模块化、流程可控及自动化校验等优势,成为开发者的优选工具。
|
开发框架 安全 前端开发
Go Web开发框架实践:模板渲染与静态资源服务
Gin 是一个功能强大的 Go Web 框架,不仅适用于构建 API 服务,还支持 HTML 模板渲染和静态资源托管。它可以帮助开发者快速搭建中小型网站,并提供灵活的模板语法、自定义函数、静态文件映射等功能,同时兼容 Go 的 html/template 引擎,具备高效且安全的页面渲染能力。
|
JSON 编解码 API
Go语言网络编程:使用 net/http 构建 RESTful API
本章介绍如何使用 Go 语言的 `net/http` 标准库构建 RESTful API。内容涵盖 RESTful API 的基本概念及规范,包括 GET、POST、PUT 和 DELETE 方法的实现。通过定义用户数据结构和模拟数据库,逐步实现获取用户列表、创建用户、更新用户、删除用户的 HTTP 路由处理函数。同时提供辅助函数用于路径参数解析,并展示如何设置路由器启动服务。最后通过 curl 或 Postman 测试接口功能。章节总结了路由分发、JSON 编解码、方法区分、并发安全管理和路径参数解析等关键点,为更复杂需求推荐第三方框架如 Gin、Echo 和 Chi。
|
开发框架 JSON 中间件
Go语言Web开发框架实践:使用 Gin 快速构建 Web 服务
Gin 是一个高效、轻量级的 Go 语言 Web 框架,支持中间件机制,非常适合开发 RESTful API。本文从安装到进阶技巧全面解析 Gin 的使用:快速入门示例(Hello Gin)、定义 RESTful 用户服务(增删改查接口实现),以及推荐实践如参数校验、中间件和路由分组等。通过对比标准库 `net/http`,Gin 提供更简洁灵活的开发体验。此外,还推荐了 GORM、Viper、Zap 等配合使用的工具库,助力高效开发。
|
设计模式 缓存 算法
Go如何进行高质量编程与性能调优实践
本文介绍了Go语言高质量编程与性能调优的实践方法。高质量编程包括良好的编码习惯(如清晰注释、命名规范)、代码风格与设计(如MVC模式)、简洁明了的代码原则,以及单元测试与代码重构的重要性。性能调优方面,涵盖算法优化、数据结构选择、I/O优化、内存管理、并行与并发处理优化及代码层面的改进。通过这些方法,可有效提升代码质量和系统性能。
307 13

热门文章

最新文章