Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Zero to Hacker Hero

Avatar for Garrett Garrett
October 18, 2014

Zero to Hacker Hero

A crash course in becoming and training web app vulnerability assessors.

Avatar for Garrett

Garrett

October 18, 2014

Other Decks in Technology

Transcript

  1. What  are  we  going  to  be  talking   about?  

    —  Share  some  of  the  techniques  I  use  to  help  people   learn  vulnerabilities.   —  Go  over  the  vulnerabilities  people  have  the  hardest   time  with.   —  Go  over  some  tips  for  putting  that  knowledge  to  use   now  in  bug  bounties  
  2. Pen  Test  vs.  Vuln  Assessment   —  These  are  sometimes

     used  interchangeably,  but   there’s  an  important  distinction  to  be  made.   —  Penetration  tests  involve  exploiting  vulnerabilities  in   order  to  show  what  we  can  do  with  them.   —  Vulnerability  Assessments,  on  the  other  hand,  involve   finding  proof  of  vulnerabilities,  without  actually   exploiting  them.   —  This  seems  like  an  academic  difference.  Who  cares?   —  With  vulnerability  assessments,  our  learning  curve  is   much  more  gradual.   —  Bug  Bounties  want  vulnerabilities  found,  not  exploited.  
  3. What  Does  this  Mean  for  Us?   —  We  don’t

     need  to  be  super  1337  and  exploit  all  the   things.    We  just  need  to  find  vulnerabilities.   —  So  what  do  we  need  to  know?   —  How  to  find  vulnerabilities   —  Testing  safely   —  Presenting  the  POC  
  4. Web  Proxy:  You’re  Gateway  to   Web  Hacking  Heroics  

    —  When  testing  these  we’re  going  to  need  to  look  at  a   lot  of  raw  http  requests  &  responses.   —  Loading  up  a  page  in  your  browser,  and  then  pulling   up  the  source  is  super  tedious.     —  To  help  with  this,  we  can  use  a  browser  proxy  to  filter   all  of  our  traffic  through.   —  BURP,  Zed  Attack  Proxy,  Web  Scarab    
  5. GET  &  POST  Requests   GET  /thrilling.html?parameter1=value1&parameter2=value2  HTTP/1.1   Host:

     example.com   User-­‐Agent:  Mozilla/5.0  (Macintosh;  Intel  Mac  OS  X  10.8;  rv:20.0)  Gecko/20100101  Firefox/20.0   WhiteHat  Security   Accept:  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8   Accept-­‐Language:  en-­‐US,en;q=0.5   Accept-­‐Encoding:  gzip,  deflate   Connection:  keep-­‐alive           POST  /thrilling.html  HTTP/1.1   Host:  example.com   User-­‐Agent:  Mozilla/5.0  (Macintosh;  Intel  Mac  OS  X  10.8;  rv:20.0)  Gecko/20100101  Firefox/20.0  WhiteHat   Security   Accept:  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8   Accept-­‐Language:  en-­‐US,en;q=0.5   Accept-­‐Encoding:  gzip,  deflate   Connection:  keep-­‐alive   Content-­‐Type:  application/x-­‐www-­‐form-­‐urlencoded   Content-­‐Length:  35     parameter1=value1&parameter2=value2  
  6. Methodology   —  For  each  vuln  we’re  going  to:  

    —  Go  over  the  basic  concept   —  Go  over  some  ways  to  find  it   —  We’ll  summarize  the  vuln  in  terms  of  being  able  to  explain   the  vuln   —  The  Root  Problem   —  Why  it  is  Bad   —  The  Fix   —  Keep  in  mind,  we’re  looking  for  low  hanging  fruit   —  You’re  not  going  to  be  able  to  find  anything  super  obscure   from  this.   —  That’s  ok.    What  most  commonly  gets  these  sites  into   trouble  is  the  easy  stuff  that  they  miss.  
  7. Obligatory  Disclaimer   —  I’m  about  to  tell  you  how

     to  find  vulnerabilities.     Don’t  go  trying  to  find  vulnerabilities  on  random   websites  on  the  internet.   —  Only  test  sites  that  you  own,  or  that  you  have  been   given  express  permission  to  test.   —  Make  sure  you  follow  the  guidelines.       —  Don’t  exploit  vulnerabilities  you’ve  found  on  websites   you  don’t  own.   —  People  go  to  jail  for  doing  this.    Don’t  be  one  of  those   people.  
  8. Cross  Site  ScripOng   —  With  this  one,  we’re  trying

     to  stick  some  JavaScript   into  a  web  page.   —  To  do  this,  we’re  going  to  look  for  somewhere  on  the   website  where  there  is  content  that  we  have  control  of   from  the  client.    Our  two  most  common  culprits  are:   —  Query  Strings   —  POST  bodies   —  *Really  anything  in  an  HTTP  request.  
  9. XSS  –  Landing  Spaces   —  What  we  do  is

     going  to  depend  on  where  we’re   landing  on  the  page.   —  There  are  going  to  be  four  primary  spaces  that  we  can   land  in  that  allow  for  different  approaches:   —  HTML  Text  Space   —  Attribute  Space   —  Script  Space   —  URI  Space  
  10. XSS  –  Example  Landing  Spaces   <html>    <body>  

       <img  id=“logo”  src=“//site.com/logo.png”/>      <h1>Thrilling  Web  Content!</h1>    <p>contentcontent  content  contentcontent  contentcontentcontent   content  content<a  href=“//somewhere.com”   onmouseover=“funFunc(‘surelySafeUserInput’)”>  thrilling  link</a>ahfoi  ashdfo   </p>   <script>    var  thrills  =  ‘w00t’;    funFunc(huzzah){      //code  here    };   </script>   </body>   </html>  
  11. XSS  –  Text  Space   —  All  of  our  injections

     here  are  going  to  involve  getting   a  tag  onto  the  page.   —  <script>  alert(0)</script>   —  <p  onmouseover=“alert(0)”>   —  Filter  Evasion  –  Lax  HTML  Parser   —  HTML  is  not  case  sensitive:   —  <sCrIpT>  alert(0)</script>   —  You  don’t  actually  need  to  close  that  tag:   —  <p  onclick=“alert(0)”  
  12. XSS  –  AVribute  Space   —  Injections  landing  here  are

     generally  going  to  involve  breaking   out  of  the  attribute’s  value  to  add  another  attribute  or  jumping   out  of  the  tag  all  together  to  get  back  into  text  space.   —  <input  type=“text”  name=“address”  value=“”onfocus=“alert(0)”/>   —  <a  href=“site.com/place/userinput”><script>alert(0)</ script>”>legit  link</a>   —  Filter  Evasion  –  Using  HTML  Entities   —  <input  type=“text”  name=“address”   value=“”onfocus=“alert&#x28;0&#x29;”/>   —  Keep  in  mind  that  you  can  not  use  the  encoding  of  a  space  to  break   out  of  a  space.  So  none  of  this:   <a  href=“site.com/place/userinput&quot;><script>alert(0)</ script>”>legit  link</a>  <!-­‐-­‐  DOESN’T  WORK!!!-­‐-­‐>  
  13. XSS  -­‐  URI  Space   —  Generally,  we  can  treat

     this  one  like  attribute  space,   by  breaking  out  and  injecting  a  new  attribute.   —  If  we  have  control  of  the  beginning  of  the  URI  space,   we  can  use  the  JavaScript  scheme.   —  <a  href=“javascript:alert(0)”>Legit  Link</a>   —  Filter  Evasion  –  URL  encodings   —  <isindex  action=“javascript:aler%74%280%29”>  
  14. XSS  –  Script  Space   —  A  lot  of  these

     are  going  to  involve  breaking  out  of  a  string,   and  sticking  some  code  in  that  will  be  executed.   —  The  trick  with  script  space  is  that  everything  must  be   syntactically  correct,  or  our  browser’s  JS  parser  will  toss   the  whole  block.  For  example,  consider  the  following  JS   code:   —  var  hax  =  “userInput”;alert(0);”;  ßNo  Good!   —  var  hax  =  “userInput”;alert(0);//”;ß  Commented  Out   —  var  hax  =  “userInput”;alert(0);"”;  ß  Quote  Paired  Up   —  Filter  Evasion  –  Unicode  Escapes   —  aler\u0074();  
  15. XSS  -­‐  Summary   —  Root  Problem:  User  input  is

     showing  up  on  a  web   page  somewhere  without  being  validated  first.   —  Why  this  is  Bad:  We  can  run  arbitrary  JavaScript  at   this  point.    Anything  JavaScript  can  do,  we  can  do.     Example  exploits  include  stealing  cookies,  altering  the   page  somehow,  redirecting  the  user,  setting  up  a  key   logger,  and  CSRF.   —  The  Fix:  Depends  on  the  landing  space.    Output   encoding  will  work  in  text  space,  otherwise  we’ll  need   a  more  specific.    Generally  speaking,  very  specific   whitelists  are  a  solid  way  to  go.  
  16. CSRF   —  This  occurs  when  we  get  people  to

     submit  a  request   from  their  browser  to  do  something  for  us.   —  Consider  this  example:   <form  action=“//site.com/profile/changePass”  method=“POST”>    <input  type=“password”  name=“NewPass”  value=“”>    <input  type=“password”  name=“ConfirmPass”  value=“”>    <input  type=“submit”  value=“Change  Pass”>   </form>    <form  action=“//site.com/profile/changePass”  method=“POST”>    <input  type=“hidden”  name=“NewPass”  value=“haxs”>    <input  type=“hidden”  name=“ConfirmPass”  value=“haxs”>    <input  type=“hidden”  value=“Change  Pass”>   </form>   Form  1:   Form  2:  
  17. Example  POST  Requests   POST  /profile/changePass  HTTP  1.1   Host:

     site.com   Headers:  values   Cookies:  session=4   Content-­‐Type:  application/x-­‐www-­‐form-­‐urlencoded   Content-­‐Length:  29     NewPass=haxs&ConfirmPass=haxs     POST  /profile/changePass  HTTP  1.1   Host:  site.com   Headers:  values   Cookies:  session=4   Content-­‐Type:  application/x-­‐www-­‐form-­‐urlencoded   Content-­‐Length:  31     NewPass=12345&ConfirmPass=12345     Form  1’s  POST  request:   Form  2’s  POST  request:  
  18. The  Great  Debate   —  Before  we  go  any  further,

     there’s  something  that  must   be  cleared  up:  How  does  one  pronounce  “CSRF”.   —  There  are  three  primary  camps:   —  Say  each  letter:  C-­‐S-­‐R-­‐F   —  Slur  it  all  together:  Sea  Surf   —  Make  it  like  XSS:  XSRF   22  
  19. Defending  CSRF   —  To  prevent  CSRF,  we  need  to

     stick  something  in  the   request  that  the  attacker  won’t  know  when  prefilling   out  the  attack  form.   —  Current  Password   —  CSRF  Token   —  Not  Cookies  –  The  victim’s  browser  will  insert  that  for   the  attacker.   —  We  can  also  look  at  the  referer  header  to  see  where   this  request  was  sent  from.  
  20. TesOng  CSRF  Defenses   —  There  are  three  things  to

     try  on  current  passwords  and  CSRF   tokens.  If  any  of  them  work,  we’ve  bypassed  this  defense:   —  Try  replacing  the  value  with  a  made  up,  but  properly  formatted   value.   —  Try  removing  the  parameter’s  value.   —  Try  removing  the  parameter  all  together.   —  For  CSRF  Tokens,  make  sure  they  are  long  enough  to  not  brute   force  and  that  they  don’t  change  in  a  predictable  manner.   —  There  are  three  tests  to  see  if  the  referer  header  is  being  used   properly  for  a  defense.    Assuming  our  legitimate  referer  is   “site.com/fun.php”:   —  Remove  the  referer  header  entirely.   —  Try  “evil.com/site.com/fun.php”   —  Try  “site.com.evil.com/fun.php”  
  21. CSRF  -­‐  Summary   —  Root  Problem:  The  request  to

     do  an  authenticated   activity  is  generic.    This  enables  an  attacker  to  pre-­‐fill   out  the  required  fields  and  have  the  victim  send  the   request  and  have  it  still  work.   —  Why  This  is  Bad:  Having  a  CSRF  vulnerability  allows   attackers  to  have  users  change  things  without  their   knowledge/permission.   —  The  Fix:  Make  the  request  so  that  the  attacker  can’t   remake  a  successful  request,  either  by  adding  a  value   that  the  attacker  won’t  be  able  to  prefill  or  carefully   check  the  referer.    
  22. SQL  InjecOon   —  SQL  injection  occurs  when  the  web

     app  takes   something  from  a  request  and  drops  it  into  a  SQL   statement  without  checking  it.   —  SELECT  title,  content  FROM  articles  WHERE   id=‘1337’;   —  So  how  do  we  tell  that  this  is  indeed  what  is   happening?  
  23. The  Two  Types  of  SQLi   —  Error-­‐Based   — 

    This  occurs  when  the  web  app  sticks  SQL  syntax  errors  into   the  response  for  you  to  see.   —  SELECT  title,  content     FROM  articles     WHERE  title=‘Cats  in  the  CyberCloud!’’;   —  SELECT  title,  content     FROM  articles     WHERE  id=102  SELECT   —  Blind   —  This  occurs  when  the  web  app  is  vulnerable  to  SQLi,  but   suppresses  syntax  errors  so  that  attackers  won’t  know  there   is  SQLi  there.  
  24. Finding  Blind  SQLi   —  Math   —  SELECT  title,

     content  FROM  articles  WHERE  id=102-­‐1;   —  Logical  Operators   —  SELECT  title,  content  FROM  articles  WHERE  id=102  AND  1=1;   —  SELECT  title,  content  FROM  articles  WHERE  id=102  AND  1=0;   —  String  Concatenation   —  Concatenation  Operators   —  Plus  Sign  “+”   —  Space  “  “   —  Two  Pipes  “||”   —  SELECT  title,  content  FROM  articles  WHERE  title=‘Cats  in  the   Cyber’+’Cloud!’;  
  25. SQL  InjecOon  -­‐  Summary   —  Root  Problem:  Insufficient  sanitization

     of  user  input  is   being  put  in  a  SQL  statement.   —  Why  This  is  Bad:  Attackers  now  have  access  to  your   database.    They  can  now  pull,  alter,  delete,  or  add   whatever  data  they  want.   —  How  Does  One  Fix  SQLI:  Parameterization  
  26. Insufficient  Auth…Something   —  There  are  two  very  similar  vulnerabilities:

      —  Insufficient  Authorization   —  Insufficient  Authentication   —  Ins.  Authentication  is  bypassing  mechanisms  to  identify   yourself  to  the  website   —  Ins.  Authorization  is  doing  something  beyond  what  your   current  user  role  should  be  allowed  to  do   —  It’s  important  to  know  the  difference  to  sound  intelligent   —  …but  that’s  kind  of  abstract  and  hard  to  remember…   —  Luckily,  there’s  a  much  easier  way!  
  27. The  Two  Magic  Ins.  Auth   IdenOfying  QuesOons!!!   — 

    Should  I  be  seeing  this  content/functionality?   —  Yes  =>  Then  there’s  no  problem.    Stop  talking  to   yourself  and  move  on  to  something  else.   —  No  =>  Then  you  have  an  insufficient  Auth.  Issue,  but   which  one?    That’s  where  question  two  comes  in.   —  Do  I  have  to  be  logged  in  to  see  this?   —  Yes  =>  Insufficient  Authorization   —  No  =>  Insufficient  Authentication  
  28. Tips  for  Finding  Ins.  Auth.   —  Try  to  get

     to  all  the  logged  in  pages  without  logging  in   first.    If  one  of  them  loads,  you  just  found  an   insufficient  authentication  issue.   —  When  looking  at  your  information,  do  you  see  an  id   number  somewhere?    Try  changing  that  number.    If   you  suddenly  see  different  information  that  isn’t   yours,  you  just  found  insufficient  authorization.   —  Find  insufficient  authorization?  Try  clearing  out  all   your  session  data  and  trying  it.    If  it  works,  you  just   escalated  to  an  authentication  issue.  
  29. Common  VulnerabiliOes   —  URL  Redirection   —  This  occurs

     when  we  can  change  where  a  user  is  sent  or   where  the  page  fetches  resources  from.   —  Insufficient  Transport  Layer  Protection   —  This  happens  whenever  you  see  sensitive  information   sent  hover  HTTP  rather  than  HTTPS   —  Content  Spoofing   —  Like  XSS,  except  we  just  stick  HTML  or  Text  into  the   page.  
  30. More  Common  VulnerabiliOes   —  Insufficient  Anti-­‐Automation   —  Occurs

     when  there  is  no  defense  against  things  being   automated.   —  An  Abuse  of  Functionality   —  When  submitting  one  of  these  forms,  do  you  see  a   parameter  in  the  request  that  controls  who  the  form   goes  to?    Change  it  to  your  own.    If  you  get  it,  you  just   found  an  abuse  of  contact  us  functionality.   —  Insufficient  Session  Expiration   —  No  logout  button?    Logging  out  doesn’t  actually  log  you   out?    If  so,  you  just  found  this  one.  
  31. ProducOon  Safety   —  If  you’re  testing  a  web  site,

     there’s  a  chance  you  might  be   testing  a  live  one.     —  When  testing  a  production  website,  it’s  important  that  you   test  it  carefully,  so  as  not  to  break  it  or  otherwise  damage   other  user’s  experience.   —  Why  is  this  important?   —  We’re  trying  to  make  the  internet  better.    Messing  up  other   people’s  use  of  a  website  makes  the  internet  worse.   —  If  you’re  trying  to  report  this  for  a  bug  bounty,  they’re   probably  not  going  to  feel  like  rewarding  you  for  breaking   their  web  site  and  losing  them  their  valued  customers.   —  If  you’re  doing  this  professionally,  your  boss  is  not  going  to   be  happy  when  all  of  your  company’s  clients  start  reporting   alert  boxes  showing  up.  
  32. ProducOon  Safety  ProTips   —  Generally  speaking,  if  there  is

     any  chance  of  affecting  the  server  or  other  users’   experience  on  a  web  site,  stay  completely  away  from  it  unless  you  know  what   you  are  doing.       —  Do  not  send  other  users’  data  to  the  company  you  are  reporting  to.    They   don’t  like  the  idea  of  their  users’  data  being  out  there.    For  finding  insufficient   authorization  type  issues  like  this,  if  possible  use  two  accounts  that  you  own.   —  Brute  forcing  functionality,  or  otherwise  hammering  the  website  with   automated  requests  is  best  avoided.    Instead  look  for  signs  that  this  activity   would  be  made  more  easily,  and  report  that.   —  For  injection  type  vulnerabilities  (XSS,  Spoofing,  etc.),  be  very  careful  with   persistent  areas.   —  Make  sure  it’s  in  a  place  that  only  you  can  see.     —  If  it’s  publically  viewable,  I  would  recommend  staying  away  from  it  in  bug   bounties.   —  If  you’re  doing  this  professionally  (ie  have  an  impressive  legal  contract),  I   would  give  it  something  innocuous,  check  to  see  if  you  can  immediately  delete   it,  and  THEN  start  playing  around  with  it.  
  33. ProducOon  Safety  ProTips   —  Things  to  stay  away  from

     when  looking  for  SQLi:   —  Comments   —  Semicolons   —  OR  1=1   —  Words  like  “DELETE”,  “DROP”,  “UPDATE”,  or  anything  else  along   those  lines   —  Timing  attacks   —  You  know  that  exciting  new  tool  you  just  found  out  about?   Don’t  use  it.   —  Many  tools  aren’t  written  with  production  safety  in  mind,  and  so   tend  to  just  hammer  the  website  with  every  possible  injection   —  Often,  websites  when  given  too  much  weird  input,  will  crash.   —  That  doesn’t  mean  you  can’t  use  tools.    Just  don’t  use  tools  unless   you  know  exactly  what  it’s  doing.  
  34. WriOng  a  Proof  of  Concept   —  We’ve  found  some

     vulnerabilities.    Now  what?    We   need  to  record  our  findings.   —  Companies  will  not  pay  out  on  bug  bounty   submissions  if  they  don’t  understand  what’s   submitted.   —  When  they  say,  “The  first  person  to  submit  will   receive  the  reward.”,  what  they  really  mean  is,  “The   first  person  to  submit  something  clear  and  concise   will  receive  the  reward.”   —  You  might  even  beat  out  somebody  who  submitted   first,  if  you  expressed  yourself  more  intelligently.  
  35. POCs  FTW   —  Briefly  describe  the  vulnerability  you  are

     reporting.   —  It  is  entirely  possible  that  you  will  be  dealing  with  someone   who  hasn’t  heard  of  the  vulnerability  you  are  describing.   —  Give  a  step  by  step  guide  of  how  to  reproduce  the   vulnerability  POC.   —  Your  steps  should  be  so  simple,  you  should  be  able  to  pull   any  random  person  off  the  street  and  that  person  should  be   able  to  hack  this  website  based  on  your  instructions.   —  Screenshots  are  a  plus,  but  don’t  overdo  it.   —  Be  sure  to  add  any  other  relevant  information  (browser   version,  date/time,  etc.)   —  Explain  why  the  vulnerability  you  are  reporting  could   negatively  impact  their  business  model.  
  36. Taking  it  to  the  Next  Level   —  WASC  Threat

     Classes   —  http://projects.webappsec.org/w/page/13246978/Threat %20Classification   —  XSS  Challenges   —  http://xss-­‐game.appspot.com/   —  http://xss-­‐quiz.int21h.jp/   —  OWASP’s  XSS  Cheat  Sheet   —  https://www.owasp.org/index.php/ XSS_Filter_Evasion_Cheat_Sheet   —  Hack  This  Site   —  https://www.hackthissite.org/   —  Spin  up  your  own  server  and  write  your  own  website.