netfilter hook하여 data 수정작업을 하는데 안됩니다. 도와주십시요.

kwonsu의 이미지

안녕하십니까. 몇일동안 이것때문에 삽질이 계속되고 있습니다. 지식이 미천하여 그러하니 고수님들의 답변을 기다립니다.

제가 하고자 하는것은 netfilter로 hooking하여 HTTP request 패킷을 잡아 data부분을 제가 바꾸고자 하는 새로운 HTTP request data로 바꾼후 클라이언트에 전송하는 것입니다.

netfilter로 hooking하여 HTTP request는 잡아서 data 수정까지는 되는걸 확인했습니다. 그런데 tcp_v4_check를 수행하였으나 동작하지 못하였습니다.

어떤 순서로 해야 할지 웹서핑에 netfilter의 ip_nat_helper.c 등 소스를 뒤져가면서 사용하기도 했지만 실패하여 이렇게 질문드립니다.

data 수정은 이렇게 하였습니다.

int  data_start = 0;
int  datalen = 0;
char *data = NULL;
char buff[512];
struct    iphdr*    ipheader   = NULL;
struct    tcphdr*   tcpheader  = NULL;
 
ipheader = (struct iphdr*)(sb->data);
tcpheader = (struct tcphdr*)( (char*)ipheader + (ipheader->ihl << 2 ) );
 
data_start = (ipheader->ihl << 2) + (tcpheader->doff <<  2);
data = (char *)sb->data + data_start
 
// buff 변수에 HTTP request header data 저장
 
strncpy( data, buff, strlen(buff) );
 
datalen = sb->len - ( ipheader->ihl << 2 );
tcpheader->check = 0;
tcpheader->check = tcp_v4_check( tcpheader, ipheader->saddr, ipheader->daddr,
                      csum_partial( (char *)tcpheader, datalen, 0 ) );

이곳 포럼에서도 검색하여 비슷한 내용을 찾아서 적용해보았으나 실패하였습니다. 물론 tcp_v4_check 함수의 인수도 조정하여 수행하였습니다.

이런 과정을 통한 후 그대로 놔두면 패킷이 목적지까지 도착하는지 아니면 패킷을 전송하는 어떠한 기능을 수행해야 하는지 모르겠습니다. 모듈프로그래밍과 netfilter는 처음하였는데 이정도 하였습니다. 생각해본거는 후킹이 끝나고 리턴할때 'return NF_ACCEPT' 하면 되지 않을까라는 생각이 들었습니다.

커널은 2.6.21버전에서 하였습니다.

고수님들의 소중한 답변 부탁드리며 이러한 비슷한 기능하는 하는 소스코드라도 몇줄이라도 부탁드립니다.

끝까지 읽어주셔서 감사합니다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.