Skip to content

Commit

Permalink
Restore connect template accidentally removed in 9fceb12b
Browse files Browse the repository at this point in the history
  • Loading branch information
zachriggle committed Feb 11, 2017
1 parent 7f5df32 commit 0bfac85
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pwnlib/shellcraft/templates/i386/linux/connect.asm
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 */

0 comments on commit 0bfac85

Please sign in to comment.