40
API DESIGN BEST PRACTICES FROM A HACKER’S VIEW

Api design best practices from a hacker's view

Embed Size (px)

Citation preview

Page 1: Api design best practices   from a hacker's view

API DESIGNBEST PRACTICES

FROM A HACKER’S VIEW

Page 2: Api design best practices   from a hacker's view

• Overview

• Stories

• CrawlallprojectsandbidsfromFreelancer.com

• Crawl6billionflightticketpricefromatravelwebsite

• Summary

Page 3: Api design best practices   from a hacker's view

MONOLITHICAPP

• Hidesysteminformationinsideapp• Nointernalsyscallisexposedtooutside

Page 4: Api design best practices   from a hacker's view

MICROSERVICEAPP

• Hackersknow your systembetter

• Servicecallsareexposedtouser

• RESTful APIasstandard, easy to guess

• Needtoconsidersecurity between every

service

Page 5: Api design best practices   from a hacker's view

TRIDITIONAL MODERN

XPATH

WEB PAGE API

Pure Data

Page 6: Api design best practices   from a hacker's view

STORY 1CRAWL FREELANCER.COM

Page 7: Api design best practices   from a hacker's view

FREELANCER.COM

8MProject Information

Bid Information

Page 8: Api design best practices   from a hacker's view

• Reputation and price, which is the most important factor for a success bid?• How can I get most chance to be awarded when bidding for Australia employer?

• Should Iputalowestpriceorshould Idomoreprojecttoearnreputation

Page 9: Api design best practices   from a hacker's view

HOW CAN I GET THE INFORMATION AS FAST AS POSSIBLE?

Page 10: Api design best practices   from a hacker's view

https://www.freelancer.com/projects/Javascript/Web-Page-Scraper/

Page 11: Api design best practices   from a hacker's view

• NeedaHTMLparserandjavascript executor

• Heavyworkforbothcpu andbandwidth

• Noteasytoiteratethroughalltheprojects

Page 12: Api design best practices   from a hacker's view

TIP: MOST OF THE TIMEMOBILE SITE IS MUCH EASIER

TOGETINFORMATION

Page 13: Api design best practices   from a hacker's view

https://m.freelancer.com/projects/Javascript/Web-Page-Scraper/#info

Page 14: Api design best practices   from a hacker's view

RESTFUL APIS

Page 15: Api design best practices   from a hacker's view

https://www.freelancer.com/api/projects/0.1/projects/Javascript%2FWeb-Page-Scraper%2F/?compact=true&full_description=true&job_details=true&location_details=true&selected_bids=true&upgrade_details=true&user_avatar=true&user_details=true&user_employer_reputation=true&user_reputation=true&user_status=true

https://www.freelancer.com/api/projects/0.1/projects/9844976/bids/?compact=true&limit=20&offset=0&reputation=true&user_avatar=true&user_details=true

https://www.freelancer.com/api/projects/0.1/projects/9844976/?compact=true&full_description=true&job_details=true&location_details=true&selected_bids=true&upgrade_details=true&user_avatar=true&user_details=true&user_employer_reputation=true&user_reputation=true&user_status=true

https://www.freelancer.com/api/projects/0.1/projects/${id}/?compact=true&full_description=true&job_details=true&location_details=true&selected_bids=true&upgrade_details=true&user_avatar=true&user_details=true&user_employer_reputation=true&user_reputation=true&user_status=true

Page 16: Api design best practices   from a hacker's view

API Rate Limit1000 / HOUR

8M/1k=8kHOUR=333DAYS

Page 17: Api design best practices   from a hacker's view

172.246.149.100216.219.130.17195.227.99.19717.124.253.149137.238.189.20734.155.214.35

• Number of threads depends on how many proxies you have• Https proxy is hard to find• Proxiesareunstable• Proxies will beusedoutquickly• High costifyoubuyproxies

WORKAROUND : USE HIGH ANONYMOUS PROXY

Page 18: Api design best practices   from a hacker's view

160.124.89.7113.193.36.236182.3.152.4485.72.136.122……

• Loads of IPs, canbe changed every 10s• Highquality socks proxiesacrosstheworld• Able to use docker to start 10 tor clients in 1 minute

WORKAROUND: USE TOR NETWORK

Page 19: Api design best practices   from a hacker's view

USINGTHESEHACKSIMANAGEDTOGETALLTHEPROJECTSANDBIDSIN10DAYS

USEASINGLEDIGITALOCEAN5$SERVER

Page 20: Api design best practices   from a hacker's view

WHAT DO I LEARN?

Page 21: Api design best practices   from a hacker's view

APIRateLimitation MobileAPI

Page 22: Api design best practices   from a hacker's view

Easytoguess filters PredicableURL

https://www.freelancer.com/api/projects/0.1/projects/Javascript%2FWeb-Page-Scraper%2F/?compact=true&full_description=true&job_details=true&location_details=true&selected_bids=true&upgrade_details=true&user_avatar=true&user_details=true&user_employer_reputation=true&user_reputation=true&user_status=true

Information leak

Page 23: Api design best practices   from a hacker's view

HOW CANWE FIX THEM?

Page 24: Api design best practices   from a hacker's view

ONLYSUPPLYINFORMATIONCLIENTNEEDS

Page 25: Api design best practices   from a hacker's view

MAKESUREURLISNOTPREDICTABLE

https://www.freelancer.com/api/projects/0.1/projects/UUID/?compact=true&full_description=true&job_details=true&location_details=true&selected_bids=true&upgrade_details=true&user_avatar=true&user_details=true&user_employer_reputation=true&user_reputation=true&user_status=true

Page 26: Api design best practices   from a hacker's view

REDUCEANONYMOUSNETWORKATTACK

• IfyourcustomersareinAUonly,restrictaccesswhenIPaddressisoutsideAU

• Setdifferentlimitationbasedonlocation

• 1k/hAPIusage • 100/hAPIusage• Captchatoverifyhuman

Page 27: Api design best practices   from a hacker's view

STORY 2LEARN FROM CAWLING FLIGHT TICKET PRICE

Page 28: Api design best practices   from a hacker's view

Howmany days ahead do I need to get a cheapest price?Ineedtocrawlasmanyflightticketpriceandanalysis.

Page 29: Api design best practices   from a hacker's view

FIND API FROMMOBILE PAGE

Page 30: Api design best practices   from a hacker's view

data=%7B%22searchType%22%3A%……

useNative=true&ttid=201300@travel_h5_3.1.0&appKey=12574478

t=1426062775998&sign=3feb52aed67967a2c47aa7a2b9f2a417Ifyouaccessthesameurl toreproduceAPIcalls,itwillafter10seconds

ANALYSEAPI

• Parameters inside data parameter:

• Fixed parameter:

• Sign

Page 31: Api design best practices   from a hacker's view

HOWCANWEGENRATEAVALIDAPICALL?

Page 32: Api design best practices   from a hacker's view

FIND TRIGGER POINT

Search source code to find API endpoint

Page 33: Api design best practices   from a hacker's view

REFORMATSOURCECODE

• Reformat code to get readablesource code

• Help to set breakpoint

Page 34: Api design best practices   from a hacker's view

FINDAPIURLGENERATOR

• Trace down the code to find out howto generate the url

Page 35: Api design best practices   from a hacker's view

FIND OUT TOKEN GENERATION ALGORITHM

• Set breakpoint andwatch variables to find out the secret

Page 36: Api design best practices   from a hacker's view

WHAT DO I LEARN?

Page 37: Api design best practices   from a hacker's view

• Use time token to generate dynamic urls

• Use parameter sign token to verify parameter

• PreventrepeatAPIcalls

• JS obfuscated code is easy to hack

Page 38: Api design best practices   from a hacker's view

SUMMARY

Page 39: Api design best practices   from a hacker's view

• Makesureurl isnotpredictable

• Onlysupplyinformationclientneeds

• Reduceanonymousnetworkattack• By different strategy to different location

• Use time token to generate dynamic url

• Use sign to verify request is valid

Page 40: Api design best practices   from a hacker's view

THANK YOU

Github: derekhe