Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
IDSECCONF	
  2013	
  CTF	
  Report	
  
by	
  Rizki	
  Wicaksono	
  /	
  ilmuHacking.com	
  
	
  
A.	
  WEB	
  HACKING	
   2	
  
A.1	
  EASY	
   2	
  
A.2	
  MEDIUM	
   2	
  
A.3	
  HARD	
   6	
  
B.	
  EXPLOITATION	
   9	
  
B.1	
  EASY	
   9	
  
B.	
  2	
  MEDIUM	
   9	
  
B.3	
  HARD	
  EXPLOIT	
   10	
  
C.	
  NETWORKING	
   13	
  
C.1	
  EASY	
   13	
  
C.2	
  MEDIUM	
   13	
  
D.	
  CRYPTOGRAPHY	
   21	
  
D.1	
  EASY	
   21	
  
E.	
  REVERSE	
  ENGINEERING	
   23	
  
E.1	
  EASY	
   23	
  
E.2	
  MEDIUM	
   24	
  
F.	
  PROGRAMMING	
   25	
  
F.1	
  EASY	
   25	
  
F.2	
  MEDIUM	
   25	
  
	
  
	
   	
  
A.	
  Web	
  Hacking	
  
A.1	
  Easy	
  
	
  
Accomplishing	
  this	
  mission	
  exploits	
  the	
  X-­‐Forwarded-­‐For	
  header.	
  PHP	
  provides	
  
$_SERVER[‘REMOTE_ADDR’]	
  variable	
  as	
  client	
  IP	
  address.	
  This	
  methods	
  perfect	
  
for	
  non-­‐proxied	
  client.	
  Unfortunately,	
  client	
  accessing	
  web	
  behind	
  proxy	
  is	
  not	
  
detected	
  with	
  this	
  method.	
  
	
  
Apparently	
  the	
  target	
  script	
  use	
  X-­‐Forwarded-­‐For	
  header	
  to	
  detect	
  client	
  address	
  
behind	
   proxy.	
   Since	
   request	
   header	
   is	
   controlled	
   by	
   attacker,	
   I	
   can	
   provide	
  
spoofed	
  address	
  to	
  make	
  me	
  looks	
  like	
  coming	
  from	
  inside	
  their	
  own	
  network.	
  
	
  
This	
  figure	
  below	
  show	
  how	
  I	
  managed	
  to	
  bypass	
  the	
  filter	
  by	
  pretending	
  to	
  be	
  
coming	
  from	
  67.220.79.46	
  address	
  using	
  X-­‐Forwarded-­‐For	
  header.	
  
	
  
	
  
A.2	
  Medium	
  
	
  
Goal	
   of	
   this	
   mission	
   is	
   to	
   get	
   system	
   information	
   of	
   the	
   target	
   server	
  
(w2.ctf.2013.idsecconf.org).	
  The	
  figure	
  below	
  is	
  its	
  index	
  page	
  with	
  detail	
  POST	
  
parameters	
  revealed	
  for	
  clarity.	
  
	
  
 
	
  
Thankfully,	
  mission	
  author	
  tIeted	
  a	
  clue	
  later	
  on	
  in	
  the	
  figure	
  below.	
  It	
  clearly	
  
shoId	
  the	
  path	
  to	
  accomplish	
  this	
  mission.	
  Apparently	
  server	
  try	
  to	
  retrieve	
  data	
  
from	
  a	
  URL,	
  decrypt	
  retrieved	
  data	
  and	
  execute	
  either	
  “date”	
  command	
  or	
  other	
  
command	
  suspected	
  to	
  be	
  “uname	
  -­‐a”	
  based	
  on	
  decrypted	
  data.	
  
	
  
	
  
	
  
POST	
  parameters	
  domain	
  and	
  file	
  are	
  together	
  combined	
  as	
  URL	
  from	
  which	
  the	
  
server	
   retrieve	
   data.	
   Since	
   retrieved	
   data	
   will	
   be	
   decrypted	
   by	
   decryptData()	
  
function,	
  data	
  that	
  will	
  be	
  retrieved	
  must	
  be	
  in	
  the	
  form	
  of	
  encrypted	
  data.	
  
	
  
I	
   are	
   given	
   with	
   default	
   value	
   of	
   domain	
   (w2.ctf.2013.idsecconf.org)	
   and	
   file	
  
parameter.	
   (psPokWxZxrUJE.txt)	
   so	
   that	
   the	
   URL	
   will	
   be	
  
http://w2.ctf.2013.idsecconf.org/psPokWxZxrUJE.txt.	
   This	
   figure	
   below	
   shows	
  
the	
  content	
  of	
  the	
  default	
  domain	
  and	
  file	
  URL.	
  
	
  
 
	
  
The	
   file	
   contents	
   is	
   base64	
   encoded	
   32	
   byte	
   size	
   ciphertext.	
   	
   What	
   facts	
   can	
  I	
  
draw	
  about	
  this?	
  	
  
• I	
  know	
  the	
  plaintext	
  of	
  this	
  ciphertext	
  is	
  either	
  date	
  or	
  uname	
  command	
  
in	
  the	
  $white	
  array	
  
• Ciphertext	
  size	
  is	
  either	
  multiple	
  of	
  8	
  or	
  16	
  byte.	
  DES	
  block	
  size	
  is	
  8	
  byte	
  
and	
  AES	
  block	
  size	
  is	
  16	
  byte.	
  If	
  it	
  was	
  DES	
  this	
  ciphertext	
  takes	
  4	
  blocks,	
  
but	
  if	
  it	
  was	
  AES	
  this	
  ciphertext	
  takes	
  2	
  blocks	
  
• I	
  are	
  sure	
  that	
  it	
  can’t	
  be	
  uname	
  command	
  because	
  it	
  will	
  be	
  padded	
  to	
  16	
  
bytes	
  in	
  DES	
  (8x2	
  blocks)	
  and	
  also	
  16	
  byte	
  in	
  AES	
  (16x1	
  block).	
  
• I	
  know	
  that	
  date	
  command’s	
  length	
  is	
  20	
  byte	
  which	
  will	
  be	
  padded	
  to	
  24	
  
byte	
  (8x3	
  blocks)	
  in	
  DES	
  or	
  will	
  be	
  padded	
  to	
  32	
  byte	
  (16x2	
  blocks)	
  in	
  
AES	
  
• Since	
  I	
  know	
  that	
  default	
  ciphertext	
  value	
  is	
  32	
  byte	
  size	
  I	
  assume	
  that	
  it	
  
was	
  an	
  AES	
  	
  (known	
  as	
  RIJNDAEL	
  in	
  PHP)	
  encrypted	
  data.	
  
	
  
Okay	
  I	
  know	
  that	
  it	
  was	
  AES	
  encryption.	
  I	
  still	
  have	
  two	
  more	
  questions.	
  What	
  is	
  
the	
  key	
  	
  and	
  mode	
  of	
  operation	
  used	
  ?	
  	
  
	
  
AES	
  have	
  two	
  popular	
  variants,	
  AES-­‐128	
  needs	
  16	
  byte	
  key	
  and	
  AES-­‐256	
  needs	
  
32	
  byte	
  key.	
  In	
  the	
  index	
  page	
  I	
  are	
  given	
  with	
  token	
  parameter	
  that	
  has	
  32	
  byte	
  
long	
  string	
  of	
  hex	
  characters.	
  This	
  token	
  size	
  match	
  match	
  with	
  AES-­‐256	
  variant,	
  
so	
  I	
  assume	
  that	
  it	
  must	
  be	
  AES-­‐256	
  encryption.	
  
	
  
One	
  more	
  question	
  to	
  answer	
  is	
  what	
  the	
  mode	
  of	
  operation	
  used?	
  Is	
  it	
  CBC	
  or	
  
ECB.	
  Since	
  I	
  know	
  that	
  ciphertext	
  size	
  is	
  32	
  which	
  is	
  an	
  encrypted	
  form	
  of	
  20	
  
byte	
   of	
   plaintext	
   +	
   12	
   byte	
   of	
   padding,	
   there	
   are	
   no	
   initialization	
   vector	
   (IV)	
  
embedded	
  in	
  ciphertext.	
  Mode	
  of	
  operation	
  that	
  use	
  no	
  IV	
  is	
  ECB	
  mode.	
  
	
  
I	
   made	
   little	
   script	
   in	
   figure	
   below,	
   to	
   decrypt	
   and	
   encrypt	
   data	
   in	
   AES-­‐256	
  
operated	
  under	
  ECB	
  mode.	
  
	
  
 
	
  
	
  
This	
  figure	
  below	
  shows	
  output	
  of	
  above	
  script.	
  
	
  
	
  
	
  
I	
  have	
  prepared	
  a	
  file	
  resides	
  containing	
  encrypted	
  “uname	
  -­‐a”	
  on	
  this	
  URL:	
  
http://www.ilmuhacking.com/wp-­‐content/uploads/2013/05/kriptonite.txt	
  
	
  
Parameter	
  POST	
  domain	
  must	
  be	
  “www.ilmuhacking.com”	
  and	
  parameter	
  POST	
  
file	
  must	
  be	
  “/wp-­‐content/uploads/2013/05/kriptonite.txt”	
  to	
  make	
  the	
  target	
  
retrieve	
  data	
  from	
  my	
  URL.	
  
	
  
After	
   all	
   preparation	
   made,	
   I	
   can	
   start	
   attacking.	
   This	
   figure	
   below	
   shows	
   a	
  
successful	
  attack.	
  
 
	
  
	
  
A.3	
  Hard	
  
	
  
This	
  mission	
  start	
  with	
  a	
  url	
  which	
  says	
  “Hi,	
  I'm	
  secure	
  Webservice	
  application,	
  
you	
  can	
  connect	
  with	
  REST,XML-­‐RPC	
  or	
  SOAP”	
  :	
  
http://services.ctf.2013.idsecconf.org:8000/ctf.php	
  
	
  
Since	
  it	
  is	
  a	
  Webservice,	
  i	
  need	
  to	
  get	
  WSDL.	
  Usually	
  many	
  Web	
  service	
  products	
  
will	
  expose	
  its	
  wsdl	
  by	
  appending	
  string	
  “?wsdl”,	
  lets	
  try	
  that.	
  
	
  
	
  
	
  
Great!	
  Now	
  i	
  will	
  use	
  soapUI	
  as	
  Web	
  service	
  client	
  to	
  invoke	
  services	
  provided.	
  
	
  
	
  
getTicket	
  service	
  needs	
  a	
  valid	
  username	
  and	
  password.	
  	
  
	
  
 
	
  
I	
  start	
  by	
  brute	
  forcing	
  the	
  most	
  common	
  username	
  and	
  password	
  until	
  finally	
  
know	
   that	
   the	
   username	
   and	
   password	
   is	
   admin/admin.	
   I	
   now	
   have	
   a	
   valid	
  
ticket.	
  
	
  
	
  
	
  
The	
  author	
  of	
  this	
  challenge	
  tIeted	
  about	
  this	
  mission.	
  The	
  ticket	
  i	
  already	
  have	
  is	
  
correct	
  and	
  i	
  spotted	
  an	
  sql	
  injection	
  vulnerability	
  on	
  the	
  ID	
  parameter.	
  Strategy	
  
I	
  used	
  to	
  accomplish	
  this	
  mission	
  is	
  by	
  exploiting	
  sql	
  injection	
  vulnerability.	
  
	
  
The	
   query	
   is	
   select	
   from	
   challenge	
   table	
   so	
   I	
   know	
   that	
   this	
   source	
   code	
   is	
  
getChallenge	
  service.	
  
	
  
	
  
	
  
When	
   getChallenge	
   service	
   receive	
   invalid	
   ticket	
   it	
   respond	
   with	
   this	
   error	
  
message.	
  	
  Valid	
  request	
  must	
  be	
  submitted	
  in	
  the	
  form	
  of	
  ticket|secureRequest.	
  I	
  
already	
  have	
  ticket,	
  but	
  what	
  secureRequest	
  is	
  ?	
  
	
  
	
  
Apparently	
  secureRequest	
  will	
  be	
  decrypted	
  and	
  will	
  be	
  used	
  	
  as	
  ID	
  parameter	
  in	
  
the	
   SQL	
   query.	
   Since	
   I	
   will	
   exploit	
   SQL	
   injection,	
   I	
   have	
   to	
   submit	
   encrypted	
  
injection	
  payload.	
  
	
  
I	
   just	
   guess	
   the	
   decryptData	
   in	
   this	
   challenge	
   is	
   similar	
   to	
   the	
   one	
   used	
   in	
  
medium	
  challenge	
  since	
  it	
  has	
  the	
  same	
  function	
  name.	
  Now	
  there	
  is	
  no	
  token	
  
parameter,	
  but	
  there	
  is	
  another	
  32	
  byte	
  value	
  that	
  is	
  the	
  ticket	
  So	
  I	
  use	
  the	
  same	
  
function	
  to	
  encrypt	
  and	
  decrypt	
  as	
  medium	
  challenge	
  but	
  using	
  different	
  key.	
  
	
  
 
	
  
This	
  figure	
  below	
  is	
  the	
  script	
  I	
  made	
  to	
  exploit	
  the	
  sql	
  injection	
  vulnerability.	
  I	
  
use	
  “union	
  select”	
  and	
  subquery	
  to	
  be	
  able	
  to	
  query	
  from	
  another	
  table.	
  
	
  	
  
	
  
	
  
	
  
This	
   figure	
   below	
   shows	
   user(),	
   database()	
   and	
   tables	
   available	
   in	
   ctf2013	
  
database.	
  
	
  
	
  
	
  
The	
  key	
  is	
  inside	
  the	
  punyaadmin	
  table.	
  This	
  key	
  is	
  encrypted	
  using	
  the	
  same	
  
method	
  as	
  encrypting	
  request.	
  
 
B.	
  Exploitation	
  
B.1	
  Easy	
  
	
  
The	
  target	
  program	
  check	
  file	
  permission	
  of	
  patch.file	
  and	
  delay	
  a	
  few	
  seconds	
  
before	
  read	
  and	
  print	
  the	
  contents	
  of	
  file	
  to	
  stdout.	
  Since	
  there	
  is	
  a	
  delay	
  between	
  
checking	
  permission	
  and	
  actually	
  open	
  and	
  read	
  the	
  file,	
  i	
  can	
  trick	
  this	
  program	
  
to	
   read	
   level0.key	
   via	
   symbolic	
   link	
   just	
   after	
   the	
   program	
   successfully	
   check	
  
permission	
   and	
   before	
   the	
   program	
   read	
   the	
   file.	
   This	
   kind	
   of	
   exploitation	
   is	
  
called	
  TOCTOU	
  (time	
  of	
  check-­‐time	
  of	
  use)	
  race	
  condition	
  attack.	
  
	
  
First	
  I	
  use	
  empty	
  file	
  and	
  get	
  patch.file	
  symlinked	
  to	
  that	
  file.	
  Because	
  file	
  kosong	
  
is	
  readable	
  by	
  level0,	
  it	
  must	
  passed	
  permission	
  check.	
  Then,	
  i	
  run	
  ./level0	
  in	
  the	
  
background	
   and	
   immediately	
   invoke	
   “ln	
   -­‐f	
   -­‐s	
   level0.key	
   patch.file”	
   to	
   had	
  
patch.file	
  symlinked	
  to	
  level0.key	
  while	
  the	
  program	
  still	
  in	
  delay	
  period.	
  
	
  
The	
  figure	
  below	
  show	
  how	
  to	
  attack	
  the	
  target.	
  
	
  
	
  
	
  
B.	
  2	
  Medium	
  
	
  
This	
   target	
   program	
   called	
   wget	
   to	
   retrieve	
   level2a.key	
   in	
   the	
   URL	
  
localhost/~level2a/level2a.key.	
  Although	
  the	
  file	
  is	
  not	
  really	
  exist	
  in	
  the	
  URL,	
  
the	
  URL	
  tell	
  us	
  about	
  full	
  path	
  of	
  level2a.key	
  (/home/level2a/level2a.key).	
  
	
  
The	
  program	
  called	
  wget	
  without	
  specifying	
  absolute	
  path.	
  In	
  this	
  situation	
  I	
  can	
  
trick	
   the	
   program	
   to	
   call	
   my	
   wget	
   instead	
   of	
   the	
   real	
   wget	
   by	
   preparing	
   my	
  
malicious	
  wget	
  and	
  setting	
  PATH	
  environment	
  to	
  current	
  directory.	
  
	
  
This	
  figure	
  below	
  show	
  how	
  to	
  attack	
  this	
  target	
  program.	
  
	
  
	
  
B.3	
  Hard	
  Exploit	
  
	
  
This	
   time	
   we	
   deal	
   with	
   classic	
   buffer	
   overflow	
   situation	
   but	
   with	
   hardened	
  
environment	
   because	
   ASLR	
   is	
   activated.	
   Although	
   ASLR	
   is	
   used	
   to	
   randomize	
  
memory	
   layout,	
   actually	
   ASLR	
   in	
   32	
   bit	
   environment	
   is	
   not	
   really	
   effective	
  
because	
  the	
  address	
  is	
  still	
  highly	
  predictable.	
  
	
  
The	
   strategy	
   I	
   used	
   is	
   to	
   spray	
   environment	
   with	
   500	
   environment	
   variables	
  
consisted	
  of	
  900	
  bytes	
  NOP	
  sled	
  and	
  35	
  byte	
  shellcode	
  and	
  then	
  i	
  run	
  the	
  target	
  
program	
  with	
  return	
  address	
  of	
  one	
  of	
  those	
  environment	
  variables.	
  Hopefully	
  
the	
  return	
  address	
  hit	
  NOP	
  sled	
  and	
  eventually	
  execute	
  my	
  shellcode.	
  
	
  
envpayload.py	
  
	
  
This	
  tool	
  prints	
  to	
  stdout	
  900	
  byte	
  NOP	
  sled	
  +	
  35	
  byte	
  shellcode.	
  
	
  
	
  
	
  
injectenv.sh	
  
	
  
This	
   tool	
   inject	
   shellcode	
   into	
   500	
   environment	
   variables,	
   named	
   EGG1	
   to	
  
EGG500.	
  
	
  
	
  
	
  
This	
   figure	
   below	
   confirms	
   that	
   my	
   shellcode	
   has	
   been	
   injected	
   to	
   500	
  
environment	
  variables.	
  
	
  
 
getegg	
  
	
  
This	
   tool	
   compiled	
   outside	
   (no	
   gcc	
   on	
   the	
   target	
   box),	
   hexdump	
   copied	
   and	
  
converted	
  to	
  binary	
  using	
  xxd	
  command.	
  
	
  
	
  
	
  
	
  
	
  
This	
  tool	
  get	
  address	
  of	
  EGG250	
  environment	
  variable	
  and	
  the	
  address	
  is	
  used	
  as	
  
guess	
  for	
  return	
  address.	
  
	
  
	
  
	
  
makepayload.py	
  
	
  
This	
   tool	
   filled	
   “thefile”	
   with	
   60	
   byte	
   junk	
   and	
   return	
   address	
   specified	
   by	
  
argument	
  1.	
  
	
  
 
	
  
prepare.sh	
  
	
  
This	
  tool	
  create	
  thefile	
  using	
  address	
  of	
  EGG250	
  environment	
  variables	
  as	
  return	
  
address.	
  
	
  
	
  
	
  
Lets	
  Hack	
  it	
  
	
  
In	
   order	
   to	
   defeat	
   ASLR,	
   i	
   need	
   to	
   run	
   two	
   things:	
   prepare.sh	
   and	
   level2	
  
iteratively	
  until	
  it	
  hit	
  my	
  NOP	
  sled	
  +	
  shellcode.	
  This	
  figure	
  below	
  shows	
  it	
  hit	
  just	
  
on	
  the	
  second	
  try.	
  
	
  
	
  
	
  
	
   	
  
C.	
  Networking	
  
	
  
C.1	
  Easy	
  
	
  
There	
   are	
   3	
   files	
   PCAPNG	
   containing	
   WPA	
   handshake	
   frame.	
   Actually	
   i	
   didn’t	
  
manage	
  to	
  crack	
  network1	
  cap	
  file	
  even	
  after	
  i	
  used	
  very	
  big	
  wordlist.	
  The	
  other	
  
file,	
  network3	
  is	
  very	
  easy	
  to	
  crack	
  with	
  standard	
  wordlist.	
  
	
  
The	
   figure	
   below	
   shows	
   successful	
   attack	
   against	
   network3	
   cap	
   file	
   using	
  
aircrack-­‐ng.	
  
	
  
	
  
	
  
C.2	
  Medium	
  
	
  
The	
  scenario	
  in	
  this	
  challenge	
  is	
  OBEX	
  file	
  transfer	
  has	
  been	
  captured,	
  extract	
  the	
  
file	
  and	
  get	
  key	
  hidden	
  inside	
  the	
  file.	
  
	
  
I	
  found	
  good	
  reference	
  in	
  this	
  http://www.fbakan.de/serexxobex/Commented-­‐
Example-­‐OBEX-­‐Communication-­‐with-­‐SE-­‐K310i.txt	
   and	
   managed	
   to	
   manually	
  
extract	
  file	
  contents.	
  
	
  
Frame	
  48	
  
	
  
 
	
  
02	
  =	
  PUT	
  
1000	
  =	
  4096	
  bytes	
  length	
  
01	
  =	
  HI	
  for	
  Name	
  
0015	
  =	
  Length	
  of	
  Name	
  header	
  
0064006100740061002e007400780074	
  =	
  data.txt	
  
0000c3	
  =	
  	
  HEader,	
  length	
  object	
  
000010f5	
  =	
  total	
  length	
  of	
  file	
  =	
  4341	
  
48	
  =	
  content	
  of	
  file	
  
0fe3	
  =	
  length	
  of	
  body	
  part	
  (4067)	
  
976	
  byte	
  of	
  byte	
  chunk:	
  
66666438666665303030313034613436343934363030303130313030303030
31303030313030303066666462303034333030303230313031303130313031
30323031303130313032303230323032303230343033303230323032303230
35303430343033303430363035303630363036303530363036303630373039
30383036303730393037303630363038306230383039306130613061306130
61303630383062306330623061306330393061306130616666646230303433
30313032303230323032303230323035303330333035306130373036303730
61306130613061306130613061306130613061306130613061306130613061
30613061306130613061306130613061306130613061306130613061306130
61306130613061306130613061306130613061306130613061306130613061
30613061306166666330303031313038303033323030333230333031323230
30303231313031303331313031666663343030316630303030303130353031
30313031303130313031303030303030303030303030303030303031303230
33303430353036303730383039306130626666633430306235313030303032
30313033303330323034303330353035303430343030303030313764303130
32303330303034313130353132323133313431303631333531363130373232
37313134333238313931613130383233343262316331313535326431663032
34333336323732383230393061313631373138313931613235323632373238
32393261333433353336333733383339336134333434343534363437343834
39346135333534353535363537353835393561363336343635363636373638
36393661373337343735373637373738373937613833383438353836383738
38383938613932393339343935393639373938393939616132613361346135
61366137613861396161623262336234623562366237623862396261633263
33633463356336633763386339636164326433643464356436643764386439
64616531653265336534653565366537653865396561663166326633663466
35663666376638663966616666633430303166303130303033303130313031
30313031303130313031303130303030303030303030303030313032303330
34303530363037303830393061306266666334303062353131303030323031
30323034303430333034303730353034303430303031303237373030303130
32303331313034303532313331303631323431353130373631373131333232
33323831303831343432393161316231633130393233333335326630313536
323732643130613136323433346531	
  
	
  
Frame	
  49	
  
	
  
	
  
	
  
32356631313731383139316132363237323832393261333533363337333833
39336134333434343534363437343834393461353335343535353635373538
35393561363336343635363636373638363936613733373437353736373737
38373937613832383338343835383638373838383938613932393339343935
39363937393839393961613261336134613561366137613861396161623262
33623462356236623762386239626163326333633463356336633763386339
63616432643364346435643664376438643964616532653365346535653665
37653865396561663266336634663566366637663866396661666664613030
30633033303130303032313130333131303033663030666466623165636434
39636534376364346263666637366231653266316265383066653163626266
31353363653536643263616561656130393538386537376331333363313230
30303735336265333630303737653238303235663133663839326337633335
61373062636266323731323466316333313230656166323339306161613366
31336638303036626339376334316532366638633561656638396165326437
34366631303264383437363731386633613338653334353864303865303932
34613932373961623366623637373865333462663031373832626333396138
36613361666333363133646566386332643664663462333334626237636562
39663232653234353838373632343838646361616637633633646162653731
66386631666235383738616565376532303464616137633230663861663631
36396138653962623664366666303063326461396539653931323564343837
30356361636432396438656161343261383035393163363065333339323466
64306534623834353561336366313439626637393462396435643264616464
32353662656261626637373962373638663830653261633565323536323364
38636535333863313338333563386639356365656135636661646437633332
34623438626262356232366366613333653131376564333536396532326638
61313337633133663132646331396635343861313633366261393235626639
37313564343838333734393066613666353536636631653837333832333966
36366639376662643566303266656335643635653237663838396662343465
38316139333738366136623438666333396133633932656233373865653333
33346537636530663262313139326564323438656264346631383663373033
31356637643733666464666436623265323063323631663037386335316134
61643738613664373639366266373564323466393761356365666530616337
65363138666362326133633563623962	
  
	
  
Frame	
  50	
  
	
  
	
  
	
  
39366133386336356165613932346639373564356632623665326466353662
35643530373033663861386133396634666436386166306366623031303131
38656136626536333866653233366231303763313239663461333661623234
66373366623461626538393032303732336363623637663138373939323933
65623838346364633761326665333565656466313966653262373836666530
35666332356631333763363666316132646333363933653135643061656635
37643465336233386333346136306236383561363730386163343033323135
34363030333135633963373232626631656263316266663030303731613766
63313365663538663131373834656462356264326263376261363538353837
63373864366263353961623139666333643163393862303965643735346662
32623632323939393862666461366565646362323265373162303930346533
33343065636564373364656666303065306537306631363466613637656365
31663062626332623639613934393661663739663132376564653235386134
32616338326461636165336536303437323038333332396464646162663138
37633537666630303035373166386537653166383335336433626333666630
30663038663738383335326237333163353634646162646133636237623737
37313262393434303136323965323639346534376363343262623635383637
61623161666235336665306263396666303531366638316666303066303534
30663835666530386231666438323763346661646638396235376630376265
61663265623761306364653137626362353939353665653138313230393132
34393130343663633165323634643830393263356336303163316166393462
66653064376166663832373162376564373766663035316338666533333763
36626433653366656332663833643063356532326238643233353263323462
37396139393931383538613938396265363261623261393964646231623431
62373435366666353833373535306337636538353639343638643439343561
64663935643966663331353863633961613536633164326334363262306637
61373262663263396332663139333466393564396461643738636234393262
61376534643166643130666663313330376530306663353366383039666231
63663834373462666461323335313861663765323365623161373437613966
38646537383664323338353664616632363162633539323263363032663937
36633835363030373936323633363732343937323662653836633866353334
30306330363036323937653666366132373361393532346535323935653466
61626637386336313461396431613731	
  
	
  
Frame	
  51	
  
	
  
 
	
  
38353238633532356232386336636265653432363437663738643134626633
66623531353235396535626662366137383164666532336665636166653362
66303363373162333766366137383636663264386130666532306630623239
35666337373537663264666662336137383662653035376332346664623436
63373532663864356531346234643566633239613565626632636432653939
37663066393936643330326163663665323734666533383833313863626139
65306138326137323332623566643661663838616332336435373432626364
33323463313562386236373432626562393036626639303766646262616337
35616638363966623566376334366638336562306364303661336132373839
33353162373061363037313862363462393232646361653137653637373835
39303830333964613031656562353265653961363639303537386339376366
66303061663931666232336662346237656465356662333936613566303565
63336333376630346663333361313561633337316137326333616437383766
34346431363038653134343230336337333232633461306236316332386461
33373035636133326564646134396663626166386233616666386337666530
39663966313562346666646238666630303633626631653565373836373538
66306636613536643666336337326463333439306466613461303839326461
36343237663738616331336537386366306361633065303332383633663330
66633339643462663663636233393635623366383339613337633430386564
34346333303936666132346536303732343166646532633532323935336430
66333863663233643661663738663766363634666638323934666564313737
35366139653362663836336631333335633136613333363731366131613235
64323431366662393732646231353930343638376130366330656136613563
36396633663364623564616636643664646239386561386366316266353666
61616161396662623664346164636465656464326234356632646564376233
36616636626438666561323766653039306666303066303538306638306666
30306630353538663832653335656630633464366661316663343164313230
34356631613738316534623863636236636666303037376564333031336363
62366232316538666434313664386638333832646635666531376662623566
63383866656331376666303466656666383262666630306563666630306662
34353738356665333037656365626630626263343165313066313065396461
39633766363764366165653635386532343839643832633832363863666661
64383539343935363863383231383634	
  
	
  
Frame	
  52	
  
	
  
	
  
	
  
36333338616665623766633262376461393661376531646232643433353734
35346261393664633334656162316564316266316365303136363230363762
3634	
  
	
  
Frame	
  56	
  
	
  
 
	
  
02	
  =	
  PUT	
  
011b	
  =	
  283	
  bytes	
  
48	
  =	
  header	
  (content	
  of	
  file)	
  
0118	
  =	
  280	
  bytes	
  	
  
66643639633561393663373364356131336132393337366437623334666630
30323666393765363566646162666463333435336266653037343535393838
38653036633363353763633766313733633131653061643433653236646364
65356666383366346262383939666566346233353832333331666139326239
61323861303064386630396638306663306338313763626630363639326264
33613639643038666630306439366264306234316630393738353632303363
61663063653965626337366232386337663461323861303065616234636431
33343538393733306539313661383437343262366530376634616438633035
303430313861323861303033306265393435313435303037666664390a	
  
	
  
After	
  combining	
  all	
  data	
  from	
  all	
  frames	
  related	
  to	
  data	
  transfer,	
  I	
  can	
  convert	
  
those	
  bytes	
  into	
  binary	
  file.	
  
	
  
	
  
	
  
	
  
This	
  figure	
  below	
  is	
  file	
  extracted	
  from	
  OBEX	
  capture	
  file.	
  
 
	
  
The	
   key	
   is	
   not	
   apparent	
   in	
   that	
   file,	
   it	
   is	
   hidden	
   using	
   steghide,	
   one	
   of	
  
steganography	
   tools.	
   I	
   made	
   simple	
   script	
   to	
   brute	
   force	
   steghide	
   password	
  
based	
  on	
  standard	
  john	
  the	
  ripper	
  wordlist.	
  
	
  
	
  
	
  
D.	
  Cryptography	
  
	
  
D.1	
  Easy	
  
	
  
I	
  use	
  this	
  simple	
  script	
  to	
  brute	
  force	
  possible	
  shift	
  count	
  in	
  julius	
  cipher.	
  
	
  
 
	
  
This	
  figure	
  below	
  shows	
  a	
  valid	
  key	
  found,	
  27.	
  
	
  
	
  
	
  
Even	
   though	
   the	
   text	
   is	
   not	
   perfectly	
   decrypted,	
   the	
   decrypted	
   text	
   is	
   good	
  
enough	
  to	
  be	
  googled.	
  That	
  text	
  is	
  a	
  poem	
  created	
  by	
  rendra.	
  
	
  
 
E.	
  Reverse	
  Engineering	
  
E.1	
  Easy	
  
	
  
The	
   goal	
   of	
   this	
   challenge	
   is	
   to	
   find	
   password.	
   Here	
   is	
   the	
   main	
   function	
  
disassembled	
  in	
  GDB.	
  
	
  
	
  
	
  
	
  
	
  
On	
  main+38	
  the	
  program	
  call	
  scanf	
  and	
  stored	
  inputted	
  value	
  in	
  EAX	
  register.	
  
Later,	
  on	
  main+52,	
  a	
  cmp	
  instruction	
  compare	
  EAX	
  register	
  (the	
  value	
  inputted	
  
by	
  user)	
  with	
  0x56C1FAE	
  value.	
  This	
  comparison	
  leads	
  to	
  two	
  branches	
  of	
  code:	
  
• Jump	
  to	
  main+77	
  and	
  print	
  string	
  stored	
  in	
  address	
  0x80485d9	
  which	
  is	
  
“Password	
  Salah	
  gan!”	
  
• Continue	
   to	
   main+54	
   and	
   print	
   formatted	
   string	
   stored	
   in	
   address	
  
0x80485b8	
  which	
  is	
  “Yeah,	
  itulah	
  Flag/key	
  kamu!	
  %d	
  n”	
  
	
  
Based	
  on	
  this	
  condition	
  and	
  branches	
  I	
  know	
  that	
  the	
  key	
  must	
  be	
  0x56C1FAE	
  or	
  
90972078	
  in	
  decimal.	
  
E.2	
  Medium	
  
	
  
The	
  goal	
  of	
  this	
  challenge	
  is	
  to	
  find	
  serial	
  number	
  for	
  our	
  own	
  username.	
  Lets	
  
start	
  debugging	
  it	
  with	
  gdb.	
  
	
  
	
  
	
  
The	
  most	
  important	
  part	
  is	
  when	
  this	
  program	
  call	
  strcmp	
  to	
  compare	
  the	
  right	
  
key	
  and	
  the	
  key	
  inputted	
  by	
  user.	
  Lets	
  add	
  breakpoint	
  at	
  that	
  point.	
  
	
  
	
  
	
  
I	
  run	
  this	
  program	
  with	
  username	
  “abcd”.	
  Just	
  right	
  before	
  strcmpt	
  called,	
  we	
  can	
  
see	
  what	
  RSI	
  registers	
  pointed	
  to.	
  RSI	
  register	
  point	
  to	
  address	
  of	
  string	
  “2345”,	
  
and	
  apparently	
  this	
  is	
  the	
  serial	
  number	
  for	
  “abcd”.	
  
 
	
  
From	
  my	
  last	
  trial	
  and	
  a	
  few	
  other	
  trials,	
  I	
  know	
  that	
  serial	
  number	
  formula	
  of	
  a	
  
given	
   username	
   is	
   just	
   like	
   julius	
   caesar	
   cipher	
   with	
   -­‐47	
   as	
   key.	
   My	
   own	
  
username	
   is	
   “kriptonite”,	
   so	
   I	
   can	
   easily	
   find	
   serial	
   number	
   by	
   shifting	
   each	
  
character	
  47	
  times	
  to	
  the	
  left.	
  	
  The	
  serial	
  for	
  user	
  kriptonite	
  is	
  “<C:AE@?:E6”	
  and	
  
the	
  key	
  is	
  ascii	
  code	
  for	
  each	
  serial	
  character.	
  
	
  
	
  
	
  
F.	
  Programming	
  
F.1	
  Easy	
  
	
  
In	
  this	
  challenge	
  we	
  must	
  find	
  the	
  10131337th	
  prime	
  number.	
  I	
  use	
  very	
  naïve	
  
strategy,	
  i	
  generate	
  around	
  all	
  prime	
  numbers	
  from	
  2	
  upto	
  200	
  million.	
  I	
  use	
  the	
  
following	
   code	
   to	
   generate	
   prime	
   numbers	
   (	
   the	
   source	
   borrowed	
   from	
  
http://rebrained.com/?p=458	
  )	
  .	
  
	
  
	
  
	
  
It	
  takes	
  only	
  4minutes	
  to	
  generate	
  11	
  million	
  prime	
  numbers.	
  
	
  
	
  
	
  
After	
   generating	
   all	
   those	
   numbers,	
   I	
   can	
   easily	
   find	
   the	
   10131337th	
   prime	
  
number.	
  
	
  
	
  
F.2	
  Medium	
  
	
  
This	
   challenge	
   is	
   not	
   hard	
   because	
   I	
   already	
   have	
   list	
   of	
   prime	
   numbers.	
   My	
  
strategy	
  was	
  to	
  convert	
  PDF	
  to	
  text	
  and	
  reformatted	
  into	
  one	
  number	
  per	
  line.	
  
After	
  I	
  have	
  two	
  list,	
  one	
  with	
  prime	
  number	
  only	
  and	
  the	
  other	
  with	
  prime	
  and	
  
some	
  non-­‐prime	
  number,	
  I	
  can	
  diff	
  them	
  to	
  get	
  the	
  non-­‐prime	
  number.	
  
	
  
First	
  I	
  must	
  cut	
  my	
  list	
  because	
  my	
  list	
  is	
  too	
  much.	
  I	
  want	
  my	
  list	
  to	
  have	
  the	
  
same	
  maximum	
  number	
  as	
  given	
  in	
  CTF	
  challenge.	
  
	
  
	
  
	
  
Now,	
  I	
  am	
  ready	
  to	
  diff	
  them	
  out.	
  
	
  
	
  
	
  
The	
  key	
  is	
  concatenation	
  of	
  10849,	
  52605735,	
  and	
  190077777.	
  
	
  
	
  

More Related Content

IDSECCONF2013 CTF online Write Up