kernel의 네트워크 계층에서 ip header가 포함된 packet을 가로채고 싶습니다.

violetoov의 이미지

안녕하세요.

android 환경에서 vpn을 사용하지 않고 패킷(ip header를 포함한 패킷)을 가로채어 app에서 이용할 수 있는 방법에 대해 고민하고 있습니다.

현재 app에서 생성된 패킷이

응용계층 -> 전송 계층(tcp) -> 네트워크 계층(ip) 로 내려가면서

네트워크 계층의 ip_output.c파일의 ipqueue_xmit() 함수에서

ip header를 구성해 데이터 링크 계층으로 보내는 것 까지는 알아낸 상태입니다.

그 다음 step으로 ip haeder가 들어간 패킷을 빼돌려 데이터링크 계층으로 내보내지 않고

app에서 해당 패킷을 얻을 수 있는 방법에 대해 고민하고 있는데 감이 오질 않아 어떻게 해결하면 좋을지 의견 부탁드립니다.

twinwings의 이미지

안드로이드 프로그래밍을 안해봐서 정확히는 모릅니다만, system call을 직접 호출 가능하다면

socket(PF_PACKET , SOCK_DGRAM , htons(ETH_P_IP));
socket(PF_INET, SOCK_RAW, IPPROTO_RAW);

둘 중 하나로 소켓을 생성하시면 됩니다.

둘다 | IP header | Payload | 형식으로 데이터를 수신하게되는데 약간의 차이가 있습니다.

  1. 전자는
    • 모든 패킷을 Application에서 수신 가능
    • 커널로부터 assembly service를 받을 수 없음
  2. 후자는
    • 모든 패킷을 받지는 못함(forward 될 패킷 들)
    • 하지만 커널로부터 assembly service를 받을 수 있음

둘다 온전한 IP header를 얻을수 있구요. 예를 들면,

const int	buf_len		= 0xFFFF;
unsigned char	buffer[buf_len]	= {0,};
int		sock_packet	= 0;
int		recv_len	= 0;
struct iphdr*	hdr		= NULL;
void*		payload		= NULL;
 
sock_packet = socket(PF_PACKET , SOCK_DGRAM , htons(ETH_P_IP));
if(sock_packet < 0)
{
	perror("socket()");
	return -1;
}
 
rcv_len = recv(sock_packet , buffer , buf_len , 0);
 
hdr 	= (struct iphdr*)buffer;		/* ip header */
payload	= buffer + sizeof(struct iphdr);	/* ip payload */
Necromancer의 이미지

C로 짠다음 안드 앱에서 JNI로 호출하면 구현가능합니다.
그런데 혹시 root 권한 요구하는 시스템 콜인가요? 그럼 일반적인 방법으로는 *절대* 안됩니다. 앱 쓰는 유저들에게 폰 루팅해서 쓰라고 해야죠.

Written By the Black Knight of Destruction

twinwings의 이미지

안드로이드에서 시스템콜이 호출가능하긴 하군요.

말씀하신 것 처럼 루트권한이 필요합니다. (정확히는 SOCK_RAW 같은 permission만 있으면 되죠. 정확히 어떤 권한인지 가물가물..)

그런데

http://stackoverflow.com/questions/27983869/android-socket-permission

찾아보니, 가능한것 같은데 어떻게 생각하시는지..?

Necromancer의 이미지

폰에 usb 웹캠 연결해서 녹화프로그램 짤려고 구현하면서 알게된겁니다.
당시 video4linux 인터페이스 문서 보고 노가다질 했는데 나중에 폰 개발하는 사람에게 들은 얘기로는 제조사가 그걸 해주지 않는 한은 순정상태에서는 절대 불가능하다고 했습니다.

제조사 순정폰 상테에서는 루트권한 획득하는 길이 다 막혀있고 앱 빌드시 카메라 사용, 네트웍 사용 권한을 부여하면 루트는 아니지만 앱 실행시 그걸 사용할 수 있는 유저의 권한을 받습니다. 그리고 유저권한으로 할수있는거면 JNI로 시스템 콜 부르면 뭐든지 다 할 수 있습니다.

Written By the Black Knight of Destruction

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.