-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore connect template accidentally removed in 9fceb12b
- Loading branch information
1 parent
7f5df32
commit 0bfac85
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<% from pwnlib.shellcraft.i386 import pushstr %> | ||
<% from pwnlib.shellcraft.i386.linux import socket, socketcall %> | ||
<% from pwnlib.constants import SYS_socketcall_connect %> | ||
<% from pwnlib.util.net import sockaddr %> | ||
|
||
<%page args="host, port, network = 'ipv4'"/> | ||
<%docstring> | ||
Connects to the host on the specified port. | ||
Leaves the connected socket in edx | ||
|
||
Arguments: | ||
host(str): Remote IP address or hostname (as a dotted quad / string) | ||
port(int): Remote port | ||
network(str): Network protocol (ipv4 or ipv6) | ||
|
||
Examples: | ||
|
||
>>> l = listen(timeout=5) | ||
>>> assembly = shellcraft.i386.linux.connect('localhost', l.lport) | ||
>>> assembly += shellcraft.i386.pushstr('Hello') | ||
>>> assembly += shellcraft.i386.linux.write('edx', 'esp', 5) | ||
>>> p = run_assembly(assembly) | ||
>>> l.wait_for_connection().recv() | ||
'Hello' | ||
|
||
>>> l = listen(fam='ipv6', timeout=5) | ||
>>> assembly = shellcraft.i386.linux.connect('ip6-localhost', l.lport, 'ipv6') | ||
>>> p = run_assembly(assembly) | ||
>>> assert l.wait_for_connection() | ||
|
||
</%docstring> | ||
<% | ||
sockaddr, length, address_family = sockaddr(host, port, network) | ||
%>\ | ||
|
||
/* open new socket, save it */ | ||
${socket(network)} | ||
mov edx, eax | ||
|
||
/* push sockaddr, connect() */ | ||
${pushstr(sockaddr, False)} | ||
mov ecx, esp | ||
${socketcall(SYS_socketcall_connect, 'edx', 'ecx', length)} | ||
|
||
/* Socket that is maybe connected is in edx */ |