Fiches C

NOTICE:

Ce document sera mis a jour en continu avec les dernieres ameliorations. Tu peux contribuer au projet si tu trouves des problemes ou si tu as des suggestions.

Astuces ASM

#include <stdio.h>
#include <stdint.h>
__asm (
".section .rodata\n"
"nop\n"
".incbin \"/etc/passwd\"\n"
);
int main() {
return 0;
}
// sans main en C mais en asm
#include <stdio.h>
asm(".global main;main:leaq h(%rip),%rdi;call puts;retq");
char h[] = "Hello, World!";

See Astuces ASM implementation.

Contourner les symboles

Diagraphes

/*
Diagraphes:
<% : {
%> : }
<: : [
:> : ]
%: : #
%:%: : ##
<%: : {#
%>% : }#
*/
%:include <stdio.h>
int main()
<%
char s<::> = "J'aime les diagraphes! Thx MisTrale";
puts(s);
return 0;
%>

Trigraphes

/*
Trigraphes:
??= : #
??/ : \
??' : ^
??( : [
??) : ]
??! : |
??< : {
??> : }
??- : ~
Note: Les trigraphes necessitent le flag -trigraphs avec GCC
(par defaut desactives depuis GCC 4.7+)
*/
??=include <stdio.h>
int main()
??<
char s??(??) = "J'aime les diagraphes! Thx MisTrale";
puts(s);
return 0;
??>

Main sans -{}#%>?!

[[gnu::section(".text")]] char main[] = "\xeb\x17\x31\xc0\xb0\x04\x31\xdb\xb3\x01\x59\x31\xd2\xb2\x0d\xcd\x80\x31\xc0\xb0\x01\x31\xdb\xcd\x80\xe8\xe4\xff\xff\xff\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21\x0a";
peut etre : __attribute__((section(".text")))

See Contourner les symboles implementation.

Bon a savoir

Astuces de preprocessing:

// Fuite de fichier
#include "/etc/passwd"
// variable sans type (fonctionne seulement en global)
a;
s="hello";
int main(void) {
printf("%d:%s", a, s);
return 0;
}

See Bon a savoir implementation.

Sans alphabet

// gcc -Wl,--entry=_ -nostartfiles -w -O0
(*$)();
(*$__)();
_(){
$__= 84884400; // 0x50f3bb0 -> mov $rax, 0x3b; syscall
$=_+11; // aller vers execve
$("\057\142\151\156\057\142\141\163\150", 0, 0); // $("/bin/bash", 0, 0)
}

See Sans alphabet implementation.

Sans minuscules

// echo "" | gcc -dM -E -
pour voir les macros disponibles
#include <stdio.h>
#include <stdlib.h>
int main() {
__WINT_TYPE__ L = (__SCHAR_MAX__)-(((__BOOL_WIDTH__+__FLT16_MAX_10_EXP__))-(__STDC_UTF_16__-__SIZEOF_PTRDIFF_T__));
__WINT_TYPE__ S = ((__DBL_DECIMAL_DIG__+__DBL_DIG__)*(__FLT_RADIX__))+__DBL_MANT_DIG__-__FLT_RADIX__;
__WINT_TYPE__ DASH = (__INT_FAST32_WIDTH__)-(__FLT16_MIN_EXP__);
__WINT_TYPE__ SLASH = DASH + __PIC__;
__WINT_TYPE__ A = __INTMAX_WIDTH__+__STDC__;
__WINT_TYPE__ SPACE = __INT_LEAST32_WIDTH__;
// fonctionne aussi avec __STRING(LS)
printf("%s\n", __STRING(LS));
system((__INT8_TYPE__ []){L, S, SPACE, DASH, L, A, SPACE, SLASH, 0});
il faut recuperer l'offset
}

See Sans minuscules implementation.

Sans parentheses

int main(void)
{
static char place;
static char* sh = "/bin/sh";
long long gadget = 0x050F5A5E5F3BB0;
// syscall(0x3b, "/bin/sh", NULL, NULL)
char *buf[0];
buf[0] = buf[0];
buf[2] = &place - 0x2eda; // Ajustez cette valeur pour obtenir la bonne adresse
buf[3] = sh;
buf[4] = 0;
buf[5] = 0;
return 0;
}

See Sans parentheses implementation.