News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Upload file to FTP server (ML64.exe)

Started by davef, November 10, 2018, 10:00:06 PM

Previous topic - Next topic

davef

Hi,
I want to share my code snippet for ML64.exe Assembler (MASM64).
This is the FTP file upload example.

;(c) 2018 Dawid_vx7 - http://vx7.pl/
;Assembler MASM64 (ML64.EXE)
;FTP Upload Example
extrn ExitProcess : proc
extrn MessageBoxA : proc
extrn InternetOpenA : proc
extrn InternetConnectA : proc
extrn FtpPutFileA : proc
extrn InternetCloseHandle : proc
extrn GetLastError : proc

.const
INTERNET_OPEN_TYPE_DIRECT equ 1
INTERNET_DEFAULT_FTP_PORT equ 21
INTERNET_SERVICE_FTP equ 1
INTERNET_FLAG_PASSIVE equ 08000000h
FTP_TRANSFER_TYPE_BINARY equ 2

.data
szAgent db "PrivateClient", 0
szFTPServer db "127.0.0.1", 0
szFTPLogin db "admin", 0
szFTPPassword db "password_here", 0
hConnection dd ?
hOpen dd ?
szLocalFile db "D:\masm64\log.txt", 0
szRemoteFile db "log.txt", 0
szSuccessText db "File was uploaded.", 0


.code
Main proc

sub rsp, 28h
mov qword ptr [rsp+20h], 0
xor r9, r9
xor r8, r8
mov rdx, INTERNET_OPEN_TYPE_DIRECT
mov rcx, offset szAgent
call InternetOpenA
add rsp, 28h
test rax, rax
jz _exit
mov hOpen, eax

sub rsp, 38h
mov qword ptr [rsp+38h], 0
mov qword ptr [rsp+30h], INTERNET_FLAG_PASSIVE
mov qword ptr [rsp+28h], INTERNET_SERVICE_FTP
mov rbx, offset szFTPPassword
mov qword ptr [rsp+20h], rbx
mov r9, offset szFTPLogin
mov r8, INTERNET_DEFAULT_FTP_PORT
mov rdx, offset szFTPServer
mov ecx, hOpen
call InternetConnectA
add rsp, 38h
test rax, rax
jz _exit
mov hConnection, eax

sub rsp, 28h
mov qword ptr [rsp+20h], 0
mov r9, FTP_TRANSFER_TYPE_BINARY
mov r8, offset szRemoteFile
mov rdx, offset szLocalFile
mov ecx, hConnection
call FtpPutFileA
add rsp, 28h
test rax, rax
jz _exit

sub rsp, 8h
mov ecx, hConnection
call InternetCloseHandle
sub rsp, 8h

sub rsp, 8h
mov ecx, hOpen
call InternetCloseHandle
sub rsp, 8h

sub rsp, 28h
xor r9, r9
lea r8, szSuccessText
lea rdx, szSuccessText
xor rcx, rcx
call MessageBoxA
add rsp, 28h

_exit:
xor rcx, rcx
call ExitProcess
Main endp
end

hutch--

Compliments, this looks like good stuff. I will try and build it later.  :t

aw27

I am recycling the AM example to retrieve a secret  :shock: file from a website:


extrn ExitProcess : proc
extrn MessageBoxA : proc
extrn InternetOpenA : proc
extrn InternetConnectA : proc
extrn FtpPutFileA : proc
extrn FtpGetFileA : proc
extrn InternetCloseHandle : proc
extrn GetLastError : proc
extern GetCurrentDirectoryA : proc
extrn strlen : proc
extrn strcat : proc

INTERNET_OPEN_TYPE_DIRECT equ 1
INTERNET_DEFAULT_FTP_PORT equ 21
INTERNET_SERVICE_FTP equ 1
INTERNET_FLAG_PASSIVE equ 08000000h
FTP_TRANSFER_TYPE_BINARY equ 2
FILE_ATTRIBUTE_NORMAL equ 80h
FTP_TRANSFER_TYPE_ASCII equ 1
MAX_PATH equ 260

.data
szAgent db "PrivateClient", 0
szFTPServer db "ftp.vgpt.com", 0
szFTPLogin db "test", 0
szFTPPassword db 0
hConnection dd ?
hOpen dd ?

szTemp db "\secret.txt", 0
szRemoteFile db "\secret.txt", 0
szSuccessText db "File was downloaded.", 0
szPathToLocalFile db 512 dup(0)

.code

Main proc
sub rsp, 48h
mov ecx, MAX_PATH
lea rdx, szPathToLocalFile
call GetCurrentDirectoryA
lea rcx, szPathToLocalFile
lea rdx, szTemp
call strcat

mov qword ptr [rsp+20h], 0
xor r9, r9
xor r8, r8
mov rdx, INTERNET_OPEN_TYPE_DIRECT
mov rcx, offset szAgent
call InternetOpenA
test rax, rax
jz _exit
mov hOpen, eax

mov qword ptr [rsp+38h], 0
mov qword ptr [rsp+30h], INTERNET_FLAG_PASSIVE
mov qword ptr [rsp+28h], INTERNET_SERVICE_FTP
mov rbx, offset szFTPPassword
mov qword ptr [rsp+20h], rbx
mov r9, offset szFTPLogin
mov r8, INTERNET_DEFAULT_FTP_PORT
mov rdx, offset szFTPServer
mov ecx, hOpen
call InternetConnectA
test rax, rax
jz _exit
mov hConnection, eax

mov qword ptr [rsp+30h], 0
mov qword ptr [rsp+28h], FTP_TRANSFER_TYPE_ASCII
mov qword ptr [rsp+20h], FILE_ATTRIBUTE_NORMAL
mov r9, 0
mov r8, offset szPathToLocalFile
mov rdx, offset szRemoteFile
mov ecx, hConnection
call FtpGetFileA
test rax, rax
jz _exit

mov ecx, hConnection
call InternetCloseHandle

mov ecx, hOpen
call InternetCloseHandle

xor r9, r9
lea r8, szSuccessText
lea rdx, szSuccessText
xor rcx, rcx
call MessageBoxA

_exit:
mov ecx, ecx
call ExitProcess
Main endp

end


Note: The anonymous test account will be removed in a few days time.