Skip to content

Instantly share code, notes, and snippets.

View dbwodlf3's full-sized avatar
๐Ÿข
I may be slow to respond.

Cogi dbwodlf3

๐Ÿข
I may be slow to respond.
  • SWLAB
  • Republic of Korea
View GitHub Profile
@dbwodlf3
dbwodlf3 / clang_pattern.txt
Created December 28, 2020 00:43
clang_pattern in smc LLVM IR
================================================================================
Jmp to Data Memory. (PIE, NO-PIE ๊ด€๊ณ„ ์—†์Œ.)
=============
Pattern 1.
clang_m64_smc10.ll
%6 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%7 = bitcast i8* %6 to void (...)*
call void (...) %7()
@dbwodlf3
dbwodlf3 / x86_pattern.txt
Created December 28, 2020 00:41
x86_pattern in smc LLVM IR
================================================================================
Write Executable Memory. ์ „๋ถ€ NO-PIE ํŒจํ„ด
==========
Pattern 1.
x86_smc1.out.ll
(๋ฐ”๋กœ ์“ฐ๊ธฐ)
store i8 1, i8* @data_804807b
@dbwodlf3
dbwodlf3 / POINTER_IR.txt
Created December 27, 2020 04:45
Pointer in LLVM IR
===============================================================================
POINTER in LLVM IR
===============================================================================
1. Pointer Type
inttoptr
ptrtoint
getelementptr
bitcast
@dbwodlf3
dbwodlf3 / CUBIC_SOLVER.txt
Last active December 27, 2020 00:29
Anderson Algorithm for Pointer Analysis
===============================================================================
Anderson Algorithm
===============================================================================
0. Basic
C์–ธ์–ด์—์„œ pointer ๋Š” ๋‹ค์Œ ์„ธ๊ฐ€์ง€์˜ ๊ฐ’์„ ๊ฐ€์ง„๋‹ค.
0.1 Example Code
```c
int main(){
int *pointerA;
@dbwodlf3
dbwodlf3 / CODE_CLASSIFICATION.txt
Created December 23, 2020 12:18
smc_examples
===============================================================================
SourceFiles
===============================================================================
1. x86 nasm code
1.1. x86_smc1
1.2. x86_smc2
1.3. x86_smc3
1.4. x86_smc4
1.5. x86_smc5
1.6. x86_smc6
@dbwodlf3
dbwodlf3 / SMC_IN_LIFTED_LL.txt
Last active December 10, 2020 23:17
SMC_IN_LIFTED_LL
===============================================================================
SMC Codes in LL From Binary
===============================================================================
X86, X64 Binary ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ Mcsema์„ ์ด์šฉํ•˜์—ฌ Lifting๋œ LL ํŒŒ์ผ์— ๋Œ€ํ•˜์—ฌ ์„ค๋ช…ํ•œ๋‹ค.
๋ช…๋ น์–ด ํ˜•ํƒœ์— ์˜ํ–ฅ์„ ์ฃผ๋Š” ๊ธฐ์ค€ 1.
1.1. NO-PIE SMC ์ฝ”๋“œ
1.2. PIE SMC ์ฝ”๋“œ
๋ช…๋ น์–ด ํ˜•ํƒœ์— ์˜ํ–ฅ์„ ์ฃผ๋Š” ๊ธฐ์ค€ 2.
@dbwodlf3
dbwodlf3 / SMC_LL.txt
Last active December 10, 2020 18:57
SMC_IN_LL.txt
===============================================================================
SMC Codes in C -> ll
===============================================================================
C์–ธ์–ด์—์„œ ์ž‘์„ฑํ•œ SMC ์ฝ”๋“œ๊ฐ€, LL ํŒŒ์ผ์—์„œ ๋‚˜ํƒ€๋‚˜๋Š” ํ˜•ํƒœ์— ๋Œ€ํ•˜์—ฌ ๋งํ•œ๋‹ค.
===============================================================================
1. ์ฝ”๋“œ ์˜์—ญ์„ ์ง์ ‘ ์ˆ˜์ •ํ•˜๋Š” ๊ฒฝ์šฐ
===============================================================================
1.1. PIE SMC ์ฝ”๋“œ
C์–ธ์–ด์—์„œ .text ์˜์—ญ ๋‹ค์Œ์— .data ์˜์—ญ์ด ์˜ค๋ฏ€๋กœ, offset์ด function์ธ ๊ฒฝ์šฐ ์–‘์ˆ˜์ด๊ณ 
@dbwodlf3
dbwodlf3 / SMC_IN_C.txt
Last active December 10, 2020 15:24
SMC Codes in C
===============================================================================
SMC Codes in C
===============================================================================
C์–ธ์–ด๋ฅผ ํ†ตํ•˜์—ฌ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” SMC ์ฝ”๋“œ.
===============================================================================
1. ์ฝ”๋“œ ์˜์—ญ์„ ์ˆ˜์ •ํ•˜๋Š” ๊ฒฝ์šฐ.
===============================================================================
1.1. PIE ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ.
address๊ฐ€ ๊ฒฐ์ •๋˜์ง€ ์•Š์•˜์œผ๋ฏ€๋กœ, directํ•˜๊ฒŒ ๋ช…์‹œํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ˆ˜์ •ํ•  ์ˆ˜ ์—†๋‹ค.
@dbwodlf3
dbwodlf3 / SMC.txt
Last active December 10, 2020 08:14
SMC in C
===============================================================================
C ์–ธ์–ด์—์„œ ๋‚˜ํƒ€๋‚˜๋Š” SMC ์ฝ”๋“œ.
===============================================================================
C ์–ธ์–ด์—์„œ์˜ ๋ฉ”๋ชจ๋ฆฌ ๋ชจ๋ธ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
High Address
stack (almost end of address. in gcc-x86 is 0xfffffff0, gcc-x64 is 0xfffffffffffffff0)
heap
uninitialized data
initalized data (data ์˜์—ญ)
@dbwodlf3
dbwodlf3 / PIE_AND_NO_PIE.txt
Last active December 10, 2020 18:28
PIE(PIC) and NO PIE
===============================================================================
GCC ์—์„œ PIE์™€ Non-PIE์˜ ์ง์ ‘์ ์ธ ์ฐจ์ด์ .
๋ณธ ๊ธ€์€ GCC์™€ C์–ธ์–ด์— ๋Œ€ํ•ด์„œ ๋งํ•˜๊ณ  ์žˆ๋‹ค.
๋“ค์–ด๊ฐ€๊ธฐ์— ์•ž์„œ ์ฃผ์˜ํ•  ์‚ฌํ•ญ.
1. PIE์™€ Non-PIE๋Š” ํ•˜๋“œ์›จ์–ด ์•„ํ‚คํ…์ฒ˜์˜ ๋ฌผ๋ฆฌ์ ์ธ ํŠน์„ฑ์ด ์•„๋‹ˆ๋‹ค.
2. PIE์™€ Non-PIE๋Š” ์ปดํŒŒ์ผ๋Ÿฌ์™€ Linker์˜ ์†Œํ”„ํŠธ์›จ์–ด์ ์ธ ํŠน์„ฑ์ด๋‹ค.
3. X86 ์•„ํ‚คํ…์ฒ˜์—์„œ๋Š” EIP๋ฅผ ๊ฒฝ์œ ํ•˜๋Š” ๋ช…๋ น์–ด๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์•„์„œ Helper Assembly
Procedure๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. (GCC์˜ ๊ฒฝ์šฐ get_thunk_pc, clang์˜ ๊ฒฝ์šฐ ๋ณ„๋„์˜ Procedure๋Š”
์—†๊ณ  call ๋ช…๋ น์–ด์™€ pop ๋ช…๋ น์–ด๋งŒ์œผ๋กœ ์ด๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค.)