Chatgpt如何开发webshell查杀脚本

admin 2024年11月13日22:30:41评论4 views字数 4964阅读16分32秒阅读模式
免责声明
由于传播、利用WK安全所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负
责,WK安全及作者不为此承担任何责任,一旦造成后果请自行承担!如有侵权烦请告知,我们会立即删除
并致歉。谢谢!

由于微信公众号推送机制改变了,快来星标不再迷路,谢谢大家!

Chatgpt如何开发webshell查杀脚本

学习杂记!我是刚学的小菜鸡 ,大佬们勿喷!!!

基于python开发的实用webshell检测脚本,该脚本基于监控"操作者"一些行为,对上传的文件进行检测,借助于百度webshell查杀(也可以换成其他平台)进行实时文件查杀。

先借助chatgpt找寻点思路Chatgpt如何开发webshell查杀脚本

import requests

#定义要检测的文件列表
shell_list = ['webshell.php', 'test.php', 'cmd.php', 'wso.php']

#定义要检测的路径
path_list = ['/', '/wp-admin/', '/admin/', '/login/']

#定义要检测的URL前缀
url_prefix = 'http://localhost'

#循环遍历检测
for path in path_list:
for shell in shell_list:
#构造URL
url = url_prefix + path + shell
#发起GET请求
r = requests.get(url)
#判断是否存在WebShell
if r.status_code == 200 and 'WebShell' in r.text:
print('[!] WebShell found:', url)

Chatgpt如何开发webshell查杀脚本

按照chatgpt给出的示例,主要就是对上传的文件做了个简单的webshell关键字检测,在这个基础上,我们增加对文件上传操作的监控并调用百度webshell Api进行实时查杀操作。

对于文件夹内文件莫过于增、删、改、查,而webshell来自于恶意攻击者上传的文件,所以我们对于增需要做严格的检测限制。这里我们使用python中的一个库watchdog来实现文件的实时监控,有关这个库的具体可自行百度。

还是先来借助"万能"的chatgpt来给出个Demo参考参考,看下图Chatgpt如何开发webshell查杀脚本

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class MyHandler(FileSystemEventHandler):
def on_created(self, event):
print(f"文件 {event.src_path} 被创建!")

if __name__ == "__main__":
event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, path=".", recursive=True)
observer.start()
try:
while True:
pass
except KeyboardInterrupt:
observer.stop()
observer.join()

Chatgpt如何开发webshell查杀脚本

参考gpt师傅的Demo,开始自己手撸

先安装watchdog库,导入库,需要四个函数增删改查,继续请教chat师傅,请求个Demo出来!

import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class FileEventHandler(FileSystemEventHandler):
def on_created(self, event):
print("File created: ", event.src_path)

def on_modified(self, event):
print("File modified: ", event.src_path)

def on_deleted(self, event):
print("File deleted: ", event.src_path)

def on_moved(self, event):
print("File moved from ", event.src_path, " to ", event.dest_path)

if __name__ == "__main__":
observer = Observer()
event_handler = FileEventHandler()
observer.schedule(event_handler, path='.', recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()

ok啦,基本思路和模板已经到位

先编写upload_check_file函数,调用百度webshell Api,然后对文件进行检测,判断是否为webshell,查看百度webshell Api给出的返回json结果,进行内容的提取,然后进行信息返回。

百度webshell地址:https://scanner.baidu.com/#/pages/introChatgpt如何开发webshell查杀脚本

对于上传文件,使用api更改web.zip即可实现

编写一个文件监控类,内部实现四个函数增删改查的编写。

class FileEventHandler(FileSystemEventHandler):
def __init__(self):
FileSystemEventHandler.__init__(self)

def on_moved(self, event):
if event.is_directory:
pass
#print("directory moved from {0} to {1}".format(event.src_path, event.dest_path))
else:
pass
#print("file moved from {0} to {1}".format(event.src_path, event.dest_path))

def on_created(self, event):
if event.is_directory:
print("directory created:{0}".format(event.src_path))
else:
print("file created:{0}".format(event.src_path))
upload_check_file(event.src_path)


def on_deleted(self, event):
if event.is_directory:
print("directory deleted:{0}".format(event.src_path))
else:
print("file deleted:{0}".format(event.src_path))

def on_modified(self, event):
if event.is_directory:
pass
#print("directory modified:{0}".format(event.src_path))
else:
pass
#print("file modified:{0}".format(event.src_path))

最后主函数进行调用,采用sys

if __name__ == "__main__":
addr = sys.argv[1]
observer = Observer()
event_handler = FileEventHandler()
observer.schedule(event_handler, r"%s"%addr, True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()

完整演示代码如下:

import json,requests

from watchdog.observers import Observer
from watchdog.events import *
import time,sys,os

# watchdag模块进行文件夹的监控,例如文件移动,修改上传,删除等动作,类似于phpstudy里面的 网页挂马

def upload_check_file(filename):
api = 'curl https://scanner.baidu.com/enqueue -F archive=@%s'%filename
try:
contents = os.popen(api).read()
s = json.loads(contents)
urls = s['url']
time.sleep(2)
result = requests.get(url=urls).json()
results = result[0]['data'][0]['descr']
if 'None' in results:
print(filename+'不是webshell')
else:
print(filename+'是webshell')
print(results)
os.unlink(filename)
print('此文件已被删除!')
except Exception as e:
pass


class FileEventHandler(FileSystemEventHandler):
def __init__(self):
FileSystemEventHandler.__init__(self)

def on_moved(self, event):
if event.is_directory:
pass
#print("directory moved from {0} to {1}".format(event.src_path, event.dest_path))
else:
pass
#print("file moved from {0} to {1}".format(event.src_path, event.dest_path))

def on_created(self, event):
if event.is_directory:
print("directory created:{0}".format(event.src_path))
else:
print("file created:{0}".format(event.src_path))
upload_check_file(event.src_path)


def on_deleted(self, event):
if event.is_directory:
print("directory deleted:{0}".format(event.src_path))
else:
print("file deleted:{0}".format(event.src_path))

def on_modified(self, event):
if event.is_directory:
pass
#print("directory modified:{0}".format(event.src_path))
else:
pass
#print("file modified:{0}".format(event.src_path))


if __name__ == "__main__":
addr = sys.argv[1]
observer = Observer()
event_handler = FileEventHandler()
observer.schedule(event_handler, r"%s"%addr, True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()

演示效果(脚本较菜,自行娱乐,借助于gpt师傅还可以写出更强大,功能更完善的脚本)

第二个参数是需要你监控的文件夹地址

Chatgpt如何开发webshell查杀脚本最后,希望大家也可以灵活运用起来gpt师傅!

Chatgpt如何开发webshell查杀脚本

Chatgpt如何开发webshell查杀脚本


原文始发于微信公众号(渗透安全团队):Chatgpt如何开发webshell查杀脚本

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年11月13日22:30:41
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Chatgpt如何开发webshell查杀脚本https://cn-sec.com/archives/1650502.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息