Skip to content

Instantly share code, notes, and snippets.

@hhc0null
Last active August 29, 2015 14:17
Show Gist options
  • Save hhc0null/3f07fd10dec59de885fa to your computer and use it in GitHub Desktop.
Save hhc0null/3f07fd10dec59de885fa to your computer and use it in GitHub Desktop.
!!THIS IS NOT A WRITEUP!! CODEGATE 2015 [PWN200] systemshock
// DEP, ASLR, SSP
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define not(x) (!(x))
extern char **environ;
// clean up all ENV.
void sub_40075c()
{
// Local variables.
char **rbp_10h;
for(rbp_10h = environ; rbp_10h != NULL; rbp_10h++) {
memset(rbp_10h, '\0', strlen(rbp_10h));
}
}
int main(int argc, char *argv[])
{
// Local variables.
char **rbp_140h;
int rbp_134h;
char rbp_120h[0x100];
rbp_134h = argc;
rbp_140h = argv;
sub_40075c();
rbp_120h[0] = 'i';
rbp_120h[1] = 'd';
rbp_120h[2] = ' ';
if(rbp_140h[1] == NULL) {
return 0;
}
// XXX: strcat is vulnerable.
strcat(rbp_120h, rbp_140h[1]);
for(rbp_124h = 0; (long long)rbp_124h < strlen(rbp_140h[1])+3; rbp_124h++) {
// isalnum from ctype.h
if(not(isalnum(rbp_120h[rbp_124h])) || rbp_120h[rbp_124h] != ' ') {
return 1;
}
}
return system(rbp_120h);
}

メモ

 ASLR+DEP+SSP, 使えるのはalphanumと' 'だけ.
 argv[1]にある文字列について, cmd[X] = "id "; strcat(cmd, argv[1]); system(cmd);を実行する. アルファベットと数字('0''9', 'A''Z', 'a'~'z')でもスペース(0x20)でもない場合は終了.
 ~~CVE-2014-9585をつかってvdsoから攻めていくと予想. CVE-2014-9585はASLR有効下でもvdsoのアドレスのエントロピーに偏りがあるという脆弱性. これで, libcベースを推測して……, って手順だと思う.~~~
 ^違った
 ulimit -m unlimitedでスタックのASLRを無効化できます.
 canaryはsystem("id "+"AAAA...AA"+canary);になるように調整すればリーク可能かも. strlen(rbp_140h);なのでオッケー.
 もしかしてcanaryに偏りがあるのかも?
 

  • まず, systemがあるのでsystem("/bin/sh");をしたい.
  • "/bin/sh"はlibcから引っ張ってくるのが一番楽.
  • 別のパターンを考えると, ROP stager+shellcode, ret2libc, だけど結局はlibcのベースをみつける必要がある.
  • ただ, 何をするにもそもそもcanaryがわからないとどうしようもない.
    • canaryをリークするにはスタックベースを把握すべき
    • writeとかそういうのでリークせねば
    • ↑使えるの無いじゃん……
  • もうこれリークできないならret2dl-resolveくらいしかないんじゃね??
  • vsyscallのgadgetが0xffffffffff600808にあるっぽい
  • strcat()が'\0'が使えないしクソw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment