2012. 11. 6. 22:45

#define LOWORD(l) ((WORD)(l))  //하위 4바이트

#define HIWORD(l) ((WORD(***DWORD)(l)>>16) & 0xffff)) --상위 4바이트

#define LOBYTE(w) ((BYTE)(w)) //하위 2바이트

#define HIBYTE(w) ((BYTE)(((WORD)(w)>>8)&0xff)) //상위 2바이트


ex)

if(LOBYTE((&char__content_type)[v14]==43)


Posted by k1rha
2012. 11. 6. 17:24

 

그냥 check 섬이라는 말도 있고 여기서 말하는대로라면 무결성을 위한 고유한 디바이스 값정도가 될듯하다..

 

Posted by k1rha
2012. 11. 6. 15:41

펌웨어에서 디바이스 제어 시 read() write() 만으로 해결 안되는 문제에 도달했을때 우리는 ioctl() 을 사용하여 해결 할수 있다.

 

[출처 : http://wiki.kldp.org/KoreanDoc/html/EmbeddedKernel-KLDP/device-understanding.html]

 

모듈은 등록될 때 디바이스 번호를 등록하고 이와 함께 file_operations 라는 구조체를 커널에 알려준다. file_operations는 include/linux/fs.h에 정의되어 있고 다음과 같다.

/*
 * NOTE:
 * read, write, poll, fsync, readv, writev can be called
 *   without the big kernel lock held in all filesystems.
 */
struct file_operations {
	struct module *owner;
	loff_t (*llseek) (struct file *, loff_t, int);
	ssize_t (*read) (struct file *, char *, size_t, loff_t *);
	ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
	int (*readdir) (struct file *, void *, filldir_t);
	unsigned int (*poll) (struct file *, struct poll_table_struct *);
	int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
	int (*mmap) (struct file *, struct vm_area_struct *);
	int (*open) (struct inode *, struct file *);
	int (*flush) (struct file *);
	int (*release) (struct inode *, struct file *);
	int (*fsync) (struct file *, struct dentry *, int datasync);
	int (*fasync) (int, struct file *, int);
	int (*lock) (struct file *, int, struct file_lock *);
	ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
	ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
	ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
	unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
};

 

 

 

 

 

int main()
{
int fd; char buf[256];

fd = open("/dev/hdd_info", O_RDWR);
ioctl(fd, 0, buf);

printf("buf : %s\n", buf);
close(fd);
return 0;
}

 

ioctl로 장치에게 동작 명령 내리고 출력하고 다시 장치를 닫는 코드이다.

 

ioctl은 장치에게 그냥 이미 정의되어있는 명령을 내리는(함수를 호출하는) 놈이라는 것을 알게 되었다

대신 장치를 우선 open으로 열고 인자로 그 file descriptor랑 가운데 request number를 넣어서 어떤 함수를 호출할지를 정하여 호출한다.

Posted by k1rha
2012. 11. 4. 16:51

[gate@localhost k1rha]$ cat test.c


 #include<stdio.h>

void func(){

printf("in function");

}

int main(int argc, char *argv[]){

char buff[10];

strcpy(buff,argv[1]);

return 0;

}

 #include<stdio.h>

void func(){

printf("in fucntion\n");

}

int main (int argc, char *argv[]){


char buff[10];

strcpy(buff,argv[1]);

return 0;

}

[gate@localhost k1rha]$ ./test `python -c 'print "x"*16+"\xf8\x83\x04\x08"'`

Segmentation fault (core dumped)

[gate@localhost k1rha]$ vi test.c   


// 여기서 개행만 추가.. 즉 1번그림에서 2번그림으로 바꿈 


[gate@localhost k1rha]$ make test

cc     test.c   -o test

[gate@localhost k1rha]$ ./test `python -c 'print "x"*16+"\xf8\x83\x04\x08"'`

in function

Segmentation fault (core dumped)

[gate@localhost k1rha]$ 


개행이 있고 없고에 차이에 따라 function이 호출되고 호출되지 않고..한다..


무슨 차이일까? ... 

Posted by k1rha
2012. 10. 31. 14:18

우선 타겟은 공유기의 펌웨어로 하여 진행을 하고 있다.

우선 펌웨어 분석툴인 firmware-mod-kit 을 이용하여 파일을 디패키징 한다. 


설치법은 다음과 같다.

(설치환경은 Ubuntu 11) 


# svn checkout http://firmware-mod-kit.googlecode.com/svn/ firmware-mod-kit-read-only

svn 을 이용하여 쭉~ 설치 .


  # cd firmware-mod-kit-read-only/

  # cd trunk/

  #  ./extract-ng.sh ../../../g1*******.bin 



 root@ubuntu:/home/iptime/toolkit/firmware-mod-kit-read-only/trunk# ./extract-ng.sh ../../../g1*******.bin 

Firmware Mod Kit (build-ng) 0.78 beta, (c)2011-2012 Craig Heffner, Jeremy Collake

http://www.bitsum.com


Scanning firmware...


DECIMAL    HEX        DESCRIPTION

-------------------------------------------------------------------------------------------------------

720896     0xB0000    Squashfs filesystem, little endian, version 3.0, size: 1201395 bytes, 243 inodes, blocksize: 65536 bytes, created: Tue Apr 12 00:55:31 2011


Extracting 720896 bytes of  header image at offset 0

Extracting squashfs file system at offset 720896

Extracting 160 byte footer from offset 1925152

Extracting squashfs files...

Firmware extraction successful!

Firmware parts can be found in 'fmk/*'


root@ubuntu:/home/****/toolkit/firmware-mod-kit-read-only/trunk/fmk/rootfs# ls -al

total 40

drwxr-xr-x 10 root root 4096 2011-04-12 00:55 .

drwxr-xr-x  5 root root 4096 2012-10-30 22:07 ..

drwxr-xr-x  3  510  504 4096 2011-04-12 00:55 bin

drwxr-xr-x  2  510  504 4096 2011-04-12 00:55 help

drwxr-xr-x  2 root root 4096 2011-04-12 00:55 images2

drwxr-xr-x  2  510  504 4096 2011-04-12 00:55 js

drwxr-xr-x  3  510  504 4096 2011-04-12 00:55 lib

drwxr-xr-x  2  510  504 4096 2011-04-12 00:55 ndbin

drwxr-xr-x  2  510  504 4096 2011-04-12 00:55 sbin

drwxr-xr-x  4  510  504 4096 2011-04-12 00:55 usr



잘 인해가 안되는것은, 같은 펌웨어 인데 버젼에 따라 패키지가 디패키징 되는 버젼이 있고 안되는 버젼이 있다는 것이다.

패킹문제인가.. 이 차이를 알고 계시는분은 연락주시면 밥한끼 사겠습니다.


E-mail :  k1rha@hacktizen.com 



Posted by k1rha
2012. 10. 30. 23:46

A good thing is that we have a neat trick to disable libc ASLR:

$ ulimit -s unlimited

$ ldd ./X79

        linux-gate.so.1 =>  (0x40020000)

        libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x4003a000)

        /lib/ld-linux.so.2 (0x40000000)

$ ldd ./X79

        linux-gate.so.1 =>  (0x40020000)

        libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x4003a000)

        /lib/ld-linux.so.2 (0x40000000)



http://leetmore.ctf.su/wp/ifsf-ctf-2012-9-x97/

Posted by k1rha
2012. 10. 28. 13:16

아래가 설치법이다.

sudo dpkg -i 파일명.deb

rpm파일은 아래의 방법으로 deb파일로 변환할 수 있다.
sudo alien -k --script 변환할파일명.rpm 

위에서 사용한 alien package가 없다면, 아래를 실행한다.
sudo apt-get update
또는
sudo apt-get install alien 
 
bin파일은 아래와 같이 실행한다.

Posted by k1rha
2012. 10. 24. 00:24

!ereg("^[\xa1-\xfe0-9a-zA-Z]+$",$name)


else if(!ereg("^[\xa1-\xfe0-9a-zA-Z]+$",$name)){
echo"
<script>
window.alert('아이디는 한글과 영문,숫자만 입력할 수 있습니다')
history.go(-1)
</script>
";
}

Posted by k1rha
2012. 10. 23. 22:03

참고로 필자의 서버환경은 32bit -  우분투 11 버젼을 활용하였다.


기본적으로 우분투는 apt-get 을 이용하여 크로스 컴파일 환경 구축을 간편하게 해줄 수 있다.


------------------------------------------------------------------------------------------

root@ubuntu:~/test# apt-get install gcc-arm-linux-gnueabi


이후 간편성을 위해 심볼릭 링크 정도 걸어두면 편하다.


root@ubuntu:~/test# whereis arm-linux-gnueabi-gcc


arm-linux-gnueabi-gcc: /usr/bin/arm-linux-gnueabi-gcc /usr/share/man/man1/arm-linux-gnueabi-gcc.1.gz



root@ubuntu:~/test# ln -s arm-gcc /usr/bin/arm-linux-gnueabi-gcc


ln: creating symbolic link `/usr/bin/arm-linux-gnueabi-gcc': File exists

root@ubuntu:~/test# ln -s /usr/bin/arm-linux-gnueabi-gcc /usr/bin/arm-gcc

root@ubuntu:~/test# arm-gcc

arm-gcc: fatal error: no input files


------------------------------------------------------------------------------------------


우분투 환경이 아닐시엔 아래와 같은 바이너리 파일로 직접 다운받아 설치 하는 방법이 있다.

http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi/


위 주소에서 크로스 컴파일 bin 파일을 wget 하여 우분투로 옮긴다.




그다음 그것을 sh 로 실행 시켜 준다.


sh [파일명.bin] 

이후 나오는 질문들은 전부 Y나 엔터로 넘어갈 수 있다.

뒤 작업은 우분투와 동일하다.







Posted by k1rha
2012. 10. 23. 00:57

mysql root 암호 분실 되어때 복구 하는 방법.

 

1. 먼저 mysql데모를 멈춘다.

# /etc/init.d/mysqld stop  또는 아래 방법

# service mysqld stop


2. mysql 강제 접속 하는 방법.

# /usr/bin/mysqld_safe --skip-grant &

# mysql -u root -p

# 엔터 하면 접속 됨.

mysql > use mysql

mysql > update user set password=password('패스워드') where user='root';

mysql > flush privileges;

Posted by k1rha