-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathelf2opcodes
More file actions
executable file
·40 lines (32 loc) · 867 Bytes
/
elf2opcodes
File metadata and controls
executable file
·40 lines (32 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl -w
#
# This script gets .text section of an object ELF file
# and shows it in hex format, perfect to add the output
# shellcode to your exploit.
#
# Very ugly perl code, but works.
#
# (c) spinfoo
# February 2006
#use strict;
die "usage: $0 prog.o\n" if $#ARGV+1 != 1;
my $file=$ARGV[0];
my $offset=`readelf -S $file |grep .text|awk '{print \$6}'`;
my $size= `readelf -S $file |grep .text|awk '{print \$7}'`;
chomp $offset;
chomp $size;
$offset= hex $offset;
$size= hex $size;
open(FILE, $file) or die "Can't open file: $file.\n";
binmode FILE;
seek(FILE, $offset, 0);
read(FILE, $buffer, $size);
close FILE;
# Dump machine code
#for ($i=0; $i < length($buffer); $i++) {
# print substr($buffer, $i, 1); }
# Dump pretty formatted shellcode
for ($i=0; $i < length($buffer); $i++) {
$a=substr($buffer, $i, 1);
printf("\\x%02x", ord $a);
}