Created
December 5, 2013 13:34
-
-
Save masami256/7805209 to your computer and use it in GitHub Desktop.
Ejectプロトコル。カーネルモジュールとしてビルドしてinsmodしたら任意のPCから"sudo sendip -p ipv4 -is 0 -f payload -ip 123 対象PCのIPアドレス"でCDドライブを開ける。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> | |
#include <linux/kernel.h> | |
#include <linux/kmod.h> | |
#include <net/protocol.h> | |
MODULE_DESCRIPTION("simple Eject protocol"); | |
MODULE_AUTHOR("masami256"); | |
MODULE_LICENSE("GPL"); | |
#define IPPROTO_NET_EJECT 123 | |
int | |
eject_handler(struct sk_buff *skb) | |
{ | |
if (skb->data && !strncmp(skb->data, "eject", 5)) { | |
char *argv[5] = {"/bin/sh", "-c", "/usr/bin/eject", "cdrom", NULL}; | |
char *envp[1] = {NULL}; | |
printk(KERN_INFO "Execute /usr/bin/eject cdrom\n"); | |
call_usermodehelper("/bin/sh", argv, envp, UMH_NO_WAIT); | |
} else { | |
printk(KERN_INFO "protocol receve unknown data\n"); | |
} | |
kfree_skb(skb); | |
return 0; | |
} | |
const struct net_protocol net_eject_protocol = { | |
.handler = eject_handler, | |
.no_policy = 1, | |
.netns_ok = 1 | |
}; | |
static int | |
net_eject_init(void) | |
{ | |
int ret = inet_add_protocol(&net_eject_protocol, IPPROTO_NET_EJECT); | |
if (!ret) | |
printk(KERN_INFO "Add protocol success\n"); | |
return ret; | |
} | |
static void | |
net_eject_cleanup(void) | |
{ | |
inet_del_protocol(&net_eject_protocol, IPPROTO_NET_EJECT); | |
printk(KERN_INFO "module unloaded\n"); | |
} | |
module_init(net_eject_init); | |
module_exit(net_eject_cleanup); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment