免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123
最近访问板块 发新帖
楼主: GNM
打印 上一主题 下一主题

贴一个能进行IP跳转欺骗的模块给大家玩玩:) [复制链接]

论坛徽章:
0
21 [报告]
发表于 2007-09-30 09:42 |只看该作者
skb->csum 是做什么用的?

论坛徽章:
0
22 [报告]
发表于 2007-09-30 10:23 |只看该作者
原帖由 platinum 于 2007-9-30 09:42 发表
skb->csum 是做什么用的?

这点我也不是太清楚,就是依葫芦画瓢

to tent8:我昨天测试检验和正常的代码是经过你修改后的测试的,我看那个size选项你不是已经调整过了么???还是说你调整过的地方还有问题???
原代码:
       size = ntohs(iph->tot_len) - (iph->ihl * 4);

        th->check = 0;
        th->check = csum_tcpudp_magic(
                iph->saddr,
                iph->daddr,
                size,
                iph->protocol,
                csum_partial(sk->h.raw, doff, sk->csum)
                );

调整后的代码:
        th->check = csum_tcpudp_magic(
                iph->saddr,
                iph->daddr,
                sk->len-tcphoff,
                iph->protocol,
                csum
                );

论坛徽章:
0
23 [报告]
发表于 2007-09-30 10:30 |只看该作者
原帖由 GNM 于 2007-9-29 20:40 发表
多谢楼上,确实检码和对了,但为什么第三次握手发起方发的是RST复位包??  我看前两次握手都正常啊,第二次返回的SYN+ACK包也都对???

20:30:26.382672 192.168.112.199.32807 > 192.168.112.180.60011: S [tcp s ...



你的问题主要处在arp 上, 网络上送包是根据MAC来的

假设 你是 192.168.9.163  往 192.168.9.179 进行TCP连接,  要将192.168.9.163 的ip 伪装成 192.168.9.6

1. 在192.168.9.179 上用arp 查看 arp表, 确定表中没有  192.168.9.6  MAC  这一表项, 有,则用 arp -d 删除

2. arp -s 192.168.9.6 MAC , 这个MAC要和 192.168.9.163相同

3. 如果192.168.9.179上开了telnet服务器, 则 在192.168.9.163上telnet 192.168.9.179, 此时可以顺利telnet上来。



enjoy :)

论坛徽章:
0
24 [报告]
发表于 2007-09-30 11:08 |只看该作者
应该不存在这种问题,我这边测试是跨网段路由的,上面贴的IP不是真识IP..

论坛徽章:
0
25 [报告]
发表于 2007-09-30 17:58 |只看该作者
搞了一天还是不行,郁闷啊.....

论坛徽章:
0
26 [报告]
发表于 2007-10-10 15:53 |只看该作者
最新进展:
通过修改代码,目前可以实现端口转换功能,但IP重定向还是有问题,三次握手最后一次最后发一个R复位.
为什么端口转换没问题,而IP就不行呢??然道我这样做理论上就有问题????请高手帮忙看看
代码访问IP:192.168.255.30:8092端口自动跳转自其60011端口,我这边测试正常)
#define _KERNEL_

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/config.h>
#include <linux/ip.h>
#include <linux/inet.h>
#include <linux/in.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>

#define ALERT(fmt,args...) printk("Test: " fmt,##args)

#define REALIP        "192.168.255.30"              /* port that appears on the wire */
//#define REALIP        "192.168.253.206"              /* port that appears on the wire */
//#define FAKEIP        "192.168.255.30"              /* port that appears on the wire */


static struct nf_hook_ops nfho_in;
static struct nf_hook_ops nfho_out;

//static unsigned char *drop_ip ="\x2a\xd7\xf1\x1";
__u32 in_aton(const char *);

unsigned long int magic_ip;
char *ip;
//MODULE_PARM(ip, "s";

static unsigned int my_call_out(unsigned int hooknum,struct sk_buff **skb,
                const struct net_device *in,
                const struct net_device *out,int(*okfn)(struct sk_buff*))
{
    struct sk_buff *sk = *skb;
    unsigned int tcphoff=sk->nh.iph->ihl*4;
    struct iphdr *iph = (*skb)->nh.iph;
    struct tcphdr *th = (struct tcphdr*)((void *)sk->nh.iph + tcphoff);
    unsigned short size;

    int csum = 0;

        if ( iph->daddr == in_aton(REALIP) && iph->protocol == IPPROTO_TCP && th->dest==htons(8092)) {

printk("test IP packet with packet to %d.%d.%d.%d \n",NIPQUAD(iph->daddr));
//        iph->daddr = in_aton(FAKEIP);
th->dest=htons(60011);
        iph->check = 0;
        iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);  

        sk->csum = 0;
        th->check = 0;
        csum = skb_checksum( sk, tcphoff ,sk->len-tcphoff , 0 );
        sk->csum = csum;

        
        th->check = csum_tcpudp_magic(
                iph->saddr,
                iph->daddr,
                sk->len-tcphoff,
                iph->protocol,
                csum
                );
        sk->ip_summed = CHECKSUM_UNNECESSARY;

        }
       // sk->ip_summed = CHECKSUM_UNNECESSARY;
   return NF_ACCEPT;
}

static unsigned int my_call_in(unsigned int hooknum,struct sk_buff **skb,
                const struct net_device *in,
                const struct net_device *out,int(*okfn)(struct sk_buff*))
{
    struct sk_buff *sk = *skb;
    unsigned int tcphoff=sk->nh.iph->ihl*4;
    struct iphdr *iph = (*skb)->nh.iph;
    struct tcphdr *th = (struct tcphdr*)((void *)sk->nh.iph + tcphoff);
    unsigned short size;

    int csum = 0;
        
        if (  iph->saddr == in_aton(REALIP)  && iph->protocol == IPPROTO_TCP && th->source==htons(60011) ) {

        printk("test IP packet with packet from %d.%d.%d.%d \n",NIPQUAD(iph->saddr));
//       iph->saddr = in_aton(FAKEIP);
th->source=htons(8092);
        iph->check = 0;
        iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);  

        sk->csum = 0;
        th->check = 0;
        csum = skb_checksum( sk, tcphoff ,sk->len-tcphoff , 0 );
        sk->csum = csum;

        
        th->check = csum_tcpudp_magic(
                iph->saddr,
                iph->daddr,
                sk->len-tcphoff,
                iph->protocol,
                csum
                );
        sk->ip_summed = CHECKSUM_UNNECESSARY;
        }
        
      
       // sk->ip_summed = CHECKSUM_UNNECESSARY;
        return NF_ACCEPT;
}

__u32 in_aton(const char *str) {
        unsigned long l;
        unsigned int val;
        int i;

        l = 0;
        for (i = 0; i < 4; i++) {
                l <<= 8;
                if (*str != '\0') {
                        val = 0;
                        while (*str != '\0' && *str != '.') {
                                val *= 10;
                                val += *str - '0';
                                str++;
                        }
                        l |= val;
                        if (*str != '\0')
                                str++;
                }
        }
        return    (htonl(l));
}




static int __init init(void)
{
        ALERT("insmod ok!\n";

              nfho_in.hook     =my_call_in ;
              nfho_in.hooknum  = NF_IP_PRE_ROUTING; /* First for IPv4 */
              nfho_in.pf       = PF_INET;
              nfho_in.priority = NF_IP_PRI_FIRST;   /* Make our func first */

              nfho_out.hook     =my_call_out ;
              nfho_out.hooknum  = NF_IP_POST_ROUTING; /* First for IPv4 */
              nfho_out.pf       = PF_INET;
              nfho_out.priority = NF_IP_PRI_FIRST;   /* Make our func first */

              nf_register_hook(&nfho_in);
              nf_register_hook(&nfho_out);

              
              return 0;

}

static void __exit fini(void)
{
        ALERT("rmsmod ok!\n";
         nf_unregister_hook(&nfho_in);
         nf_unregister_hook(&nfho_out);

}


module_init(init);
module_exit(fini);
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP