- 求职 : 通讯/电信开
- 论坛徽章:
- 2
|
各位前辈,小弟是仿照http://bbs.chinaunix.net/thread-1941060-1-1.html这位大神的第二个例子,不过不同的是我现在的版本是3.10所以有些函数改变了,运行时出现了一个错误。如下图所示:- [ 86.380000] Call Trace:
- [ 86.380000] [<802134a8>] skb_copy+0x14/0xc8
- [ 86.380000] [<8722a030>] 0x8722a030
- [ 86.380000]
- [ 86.380000]
- Code: afb00010 afbf001c afb20018 <8c8200a4> 8c8300a0 8c9200a8 00808821 240
- [ 86.590000] ---[ end trace 61c61b56e93aa6c0 ]---
- [ 91.610000] CPU 0 Unable to handle kernel paging request at virtual address 0
- [ 91.620000] Oops[#2]:
- [ 91.620000] CPU: 0 PID: 1058 Comm: ntpd Tainted: G D 3.10.49 #11
- [ 91.620000] task: 871cd920 ti: 871a8000 task.ti: 871a8000
- [ 91.620000] $ 0 : 00000000 00000000 8722a000 80112b94
- [ 91.620000] $ 4 : 00000000 00000020 00000000 8787c400
- [ 91.620000] $ 8 : 00000000 8718e824 00000000 0133076f
- [ 91.620000] $12 : 70656e77 8718e854 00000000 72740470
- [ 91.620000] $16 : 871a9bc8 802ffdbc 870cdf00 00000003
- [ 91.620000] $20 : 00000000 00000001 00000004 00000003
- [ 91.620000] $24 : 00000000 80258114
- [ 91.620000] $28 : 871a8000 871a9b18 ffffff62 8722a030
- [ 91.620000] Hi : 00000008
- [ 91.620000] Lo : 0000061a
- [ 91.620000] epc : 802134a8 skb_copy+0x14/0xc8
- [ 91.620000] Tainted: G D
- [ 91.620000] ra : 8722a030 0x8722a030
- [ 91.620000] Status: 1000f403 KERNEL EXL IE
- [ 91.620000] Cause : 00800008
- [ 91.620000] BadVA : 000000a4
- [ 91.620000] PrId : 00019374 (MIPS 24Kc)
- [ 91.620000] Modules linked in: skbtest ath9k ath9k_common pppoe ppp_async ipn
- [ 91.620000] Process ntpd (pid: 1058, threadinfo=871a8000, task=871cd920, tls)
- [ 91.620000] Stack : 803029b0 801adaa8 001a9b54 871a9b68 871a9bc8 802ffdbc 870
- 00000000 80218990 879894ac 00000000 871a9bc8 802ffdbc 870cdf00 0000003
- 00000000 00000001 00000004 801a21e8 00000000 8794a880 871a9c64 0000004
- 80112b94 00000000 8722a5b0 8718e810 870cdf00 870cdf00 00000003 802ffdc
- 00000002 00000000 00000001 801a1dac 00000028 8008e368 80302ecc 0000000
- ...
- [ 91.620000] Call Trace:
- [ 91.620000] [<802134a8>] skb_copy+0x14/0xc8
- [ 91.620000] [<8722a030>] 0x8722a030
- [ 91.620000]
- [ 91.620000]
- Code: afb00010 afbf001c afb20018 <8c8200a4> 8c8300a0 8c9200a8 00808821 240
- [ 91.830000] ---[ end trace 61c61b56e93aa6c1 ]---
- [ 96.850000] CPU 0 Unable to handle kernel paging request at virtual address 0
- [ 96.860000] Oops[#3]:
- [ 96.860000] CPU: 0 PID: 1059 Comm: ntpd Tainted: G D 3.10.49 #11
- [ 96.860000] task: 871cd920 ti: 871a8000 task.ti: 871a8000
- [ 96.860000] $ 0 : 00000000 00000000 8722a000 80112b94
- [ 96.860000] $ 4 : 00000000 00000020 00000000 8787c400
- [ 96.860000] $ 8 : 00000000 8718ec24 00000000 0133076f
- [ 96.860000] $12 : 70656e77 8718ec54 00 96.860000] $16 : 871a9bc8 802ffdb3
- [ 96.860000] $20 : 00000000 00000001 00000004 00000003
- [ 96.860000] $24 : 00000000 80258114
- [ 96.860000] $28 : 871a8000 871a9b18 ffffff62 8722a030
- [ 96.860000] Hi : 0000000d
- [ 96.860000] Lo : 000006bb
- [ 96.860000] epc : 802134a8 skb_copy+0x14/0xc8
- [ 96.860000] Tainted: G D
- [ 96.860000] ra : 8722a030 0x8722a030
- [ 96.860000] Status: 1000f403 KERNEL EXL IE
- [ 96.860000] Cause : 00800008
- [ 96.860000] BadVA : 000000a4
- [ 96.860000] PrId : 00019374 (MIPS 24Kc)
- [ 96.860000] Modules linked in: skbtest ath9k ath9k_common pppoe ppp_async ipn
- [ 96.860000] Process ntpd (pid: 1059, threadinfo=871a8000, task=871cd920, tls)
- [ 96.860000] Stack : 80301d90 801c03f0 00300000 801d552c 871a9bc8 802ffdbc 870
- 00000000 80218990 80301d90 80067ee8 871a9bc8 802ffdbc 87b9df00 0000003
- 00000000 00000001 00000004 801a21e8 00000000 8794aaa0 871a9c64 0000004
- 80112b94 00000000 8722a5b0 8718ec10 87b9df00 87b9df00 00000003 802ffdc
- 00000002 00000000 00000001 801a1dac 00000028 8008e368 00000060 8024500
- ...
复制代码- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/init.h>
- #include <linux/netfilter.h>
- #include <linux/skbuff.h>
- #include <linux/ip.h>
- #include <linux/netdevice.h>
- #include <linux/if_ether.h>
- #include <linux/if_packet.h>
- #include <linux/inet.h>
- #include <net/tcp.h>
- #include <net/udp.h>
- #include <net/icmp.h>
- #include <linux/netfilter_ipv4.h>
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("shenshenlei@163.com");
- #define ETH "eth1"
- unsigned char SMAC[ETH_ALEN] = {0x4C,0x5E,0x0C,0x85,0x06,0xA9};
- unsigned char DMAC[ETH_ALEN] = {0x00,0x0c,0x29,0x3b,0xd8,0xa9};
- static struct nf_hook_ops modify_ops;
- static unsigned int modify(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* nskb;
- struct iphdr* nip_hdr;
- unsigned int nip_hdr_off;
- struct tcphdr* ntcp_hdr;
- unsigned int ntcp_hdr_off;
- struct ethhdr* neth_hdr;
- int ret = 0;
- printk("Prepare skb_copy");
- nskb = skb_copy(*skb, GFP_ATOMIC);
- if(nskb == NULL)
- {
- printk("%s\n", "skb_copy return NULL");
- return NF_ACCEPT;
- }
- if(ip_hdr(nskb)->protocol!=IPPROTO_TCP){
- kfree_skb(nskb);
- return NF_ACCEPT;
- }
- /*
- tcp header
- */
- nip_hdr = ip_hdr(nskb);
- nip_hdr_off = nip_hdr->ihl << 2;
-
- ntcp_hdr = tcp_hdr(nskb);
- ntcp_hdr_off = ntcp_hdr->doff << 2;
- if(!ntcp_hdr->syn)
- {
- kfree_skb(nskb);
- return NF_ACCEPT;
- }
-
- //evil!
- nip_hdr->daddr = in_aton("192.168.1.168");
- nip_hdr->check = 0;
- nip_hdr->check = ip_fast_csum((unsigned char *)nip_hdr, nip_hdr->ihl);
-
- nskb->csum = csum_partial((unsigned char *)(ntcp_hdr + ntcp_hdr_off),
- ntohs(nip_hdr->tot_len) - nip_hdr_off - ntcp_hdr_off, 0);
- ntcp_hdr->check = 0;
- ntcp_hdr->check = csum_tcpudp_magic(nip_hdr->saddr, nip_hdr->daddr,
- ntohs(nip_hdr->tot_len) - nip_hdr_off, nip_hdr->protocol,
- csum_partial((unsigned char *)ntcp_hdr, ntcp_hdr_off, nskb->csum));
- nskb->ip_summed = CHECKSUM_NONE;
- nskb->pkt_type = PACKET_OTHERHOST;
-
- nskb->dev = dev_get_by_name(&init_net,ETH);
- if(nskb->dev==NULL)
- {
- printk("%s\n", "dev_get_by_name return NULL");
- kfree_skb(nskb);
- return NF_ACCEPT;
- }
- //ETH
- nskb->mac_header = skb_push(nskb, ETH_HLEN);
- { //eth headeri
- neth_hdr = (struct ethhdr *)nskb->mac_header;
- memcpy (neth_hdr->h_dest, DMAC, ETH_ALEN);
- memcpy (neth_hdr->h_source, SMAC, ETH_ALEN);
- neth_hdr->h_proto = __constant_htons (ETH_P_IP);
- }
-
- dev_hold(nskb->dev);
- printk(KERN_ERR"dev_hold ok,start xmiting");
-
- ret = dev_queue_xmit(nskb);
- printk(KERN_ERR"ret:%d\n", ret);
- return NF_STOLEN;
- }
- static int __init init(void)
- {
- int ret = 0;
- modify_ops.hook = modify;
- modify_ops.hooknum = NF_INET_LOCAL_OUT;
- modify_ops.pf = PF_INET;
- modify_ops.priority = NF_IP_PRI_FIRST;
- ret = nf_register_hook(&modify_ops);
- if (ret < 0)
- {
- printk("%s\n", "can't modify skb hook!");
- return ret;
- }
- printk("%s\n", "insmod modify skb module");
- return 0;
- }
- static void __exit fini(void)
- {
- nf_unregister_hook(&modify_ops);
- printk("%s\n", "remove modify skb module.");
- }
- module_init(init);
- module_exit(fini);
复制代码 |
|