Mostrando postagens com marcador assembly. Mostrar todas as postagens
Mostrando postagens com marcador assembly. Mostrar todas as postagens

terça-feira, 17 de abril de 2012

My first shellcode :)

/*
 * File: shello.c
 *
 * Generated from this assembly code:
 *      pushl   %ebp
 *      movl    %esp, %ebp
 *      
 *      subl    $12, %esp
 *      movl    $0x6c6c6548, -12(%ebp)
 *      movl    $0x6f57206f, -8(%ebp)
 *      movl    $0x0a646c72, -4(%ebp)
 *      
 *      movl    $4, %eax        
 *      movl    $1, %ebx
 *      leal    -12(%ebp), %ecx 
 *      movl    $12, %edx 
 *      
 *      int     $0x80
 *      addl     $12, %esp
 *      
 *      leave
 *      ret
 * 
 */

/*
 * Tested on Linux hilstdsk 3.2.7-1-ARCH #1 SMP PREEMPT Tue Feb 21
 * 16:59:04 UTC 2012 i686 AMD Athlon(tm) 64 X2 Dual Core Processor
 * 4400+ AuthenticAMD GNU/Linux
 * Archlinux
 */

/*
 * Compile: gcc -o shello shello.c
 * Run: ./shello
 * Output: Hello World
 */
 
/*
 * Thats pretty cool!
 */
#include 

static char shellcode[] = "\x55"
        "\x89\xe5"
        "\x83\xec\x0c"
        "\xc7\x45\xf4\x48\x65\x6c\x6c"
        "\xc7\x45\xf8\x6f\x20\x57\x6f"
        "\xc7\x45\xfc\x72\x6c\x64\x0a"
        "\xb8\x04\x00\x00\x00"
        "\xbb\x01\x00\x00\x00"
        "\x8d\x4d\xf4"
        "\xba\x0c\x00\x00\x00"
        "\xcd\x80"
        "\x83\xc4\x0c"
        "\xc9"
        "\xc3";

int main(void)
{
        void (*p)(void);
        p = shellcode;
        p();
        return 0;
}

sexta-feira, 21 de outubro de 2011

Perl assembly generator

I wrote a little perl script that receives input and creates an x86 assembly program. This program put all data on stack and then print it using printf c function. Useless but cool
#!/usr/bin/perl

use warnings;
use strict;

undef $/;
my $input = <>

$input = unpack("H*", $input);
my @integers;

while (length($input) > 8) {
 my $str = substr($input, 0, 8);
 $str =~ s/(.{2})(.{2})(.{2})(.{2})/$4$3$2$1/;
 push(@integers, ("0x".$str));
 $input = substr($input, 8);
}

my $buf = "";
while (length($input) > 0) {
 $buf .= substr($input, -2);
 $input = substr($input, 0, -2);
}

push(@integers, sprintf("0x%08x", hex($buf)));
my $stck_deep = ($#integers + 1) * 4;

print <<EOS
        .section        .text.startup,"ax",\@progbits
        .globl  main
        .type   main, \@function
main:
        pushl   %ebp
        movl    %esp, %ebp

 subl \$$stck_deep, %esp

 movl \$$integers[0], (%esp)
EOS
;

for my $i (1 .. $#integers) {
 printf("\tmovl \$%s, %d(%%esp)\n", $integers[$i], $i * 4); 
} 

print <<EOS
 movl \$0x0, $stck_deep(%esp)
 
 pushl %esp
 call printf
 popl %eax

 addl \$$stck_deep, %esp


 xorl %eax, %eax
 leave
 ret
EOS

;

Here is a try:
https://ideone.com/cuvXe
https://ideone.com/2oA9q
[]'s

terça-feira, 8 de março de 2011

Boot hello world

; Tell the compiler that this is the 0 address
[ORG 0] 
    jmp 07C0h:start   ; Jump to start

    msg db "Hello boot world ", 2, 0 ; My string
         ; the 2 byte should provide some fun

start: 

    ; Setting up the segment registers
    
    mov ax, cs
    mov ds, ax
    mov es, ax
    
    
    ; Writing the string 

    mov si, msg
print:    lodsb
    cmp al, 0
    je hang
    mov ah, 0Eh
    mov bx, 7
    int 010h    ; BIOS video service interrupt
    
    jmp print
    

hang:     
    jmp hang


    times 510-($-$$) db 0
    dw 0AA55h

.

I saw this here, so is not my merit..

to run:
copy this to a .asm file, e.g. b.asm, then assemble it with
$ nasm -o b.bin b.asm
and finaly write it to some pendrive with
dd if=b.bin of=/dev/YOURPENDRIVE
e.g $ dd if=b.bin of=/dev/sdc
Boot the pendrive and you should get a funny message on screen =)
if you have qemu installed you can boot directly the binary
$ qemu -hda b.bin