How to write secure code?

Protect yourself against Broken Auth & Session Management!

Aditya Anand
Mar 13, 2019 · 7 min read

Need for Secure Code?

Let’s dig in!

1. Hard-Coding login credentials

Image for post
Image for post
Insecure Code - Hard coded creds
Image for post
Image for post
Secure Code - Creds are not hard coded

2. Cookie Manipulation

Image for post
Image for post
Image for post
Image for post
Cookie details
Image for post
Image for post
Modifying cookie
Image for post
Image for post
Modified cookie
// Issue is same session object is being used so get current session
HttpSession before_login = request.getSession();
//Invalidate that session
before_login.invalidate();
//Generate a new session, new JSESSIONID
HttpSession after_login = request .getSession(true);

3. User Enumeration via Web Service

Image for post
Image for post
User does not exist
Image for post
Image for post
User does exist
Image for post
Image for post
Image for post
Image for post
Enumerated Usernames

4. Brute Force attack

Image for post
Image for post
Image for post
Image for post
Request Query
Image for post
Image for post
Brute Force attack via Burp-Suite

Moral

Broken Authentication

Session Management

Read my other article regarding “ Secure Coding Practises ”


InfoSec Write-ups

A collection of write-ups from the best hackers in the…

Aditya Anand

Written by

CyberSec Professional | Hacker | Developer | Open Source Lover | Website - aditya12anand.com | Donate - paypal.me/aditya12anand

InfoSec Write-ups

A collection of write-ups from the best hackers in the world on topics ranging from bug bounties and CTFs to vulnhub machines, hardware challenges and real life encounters. In a nutshell, we are the largest InfoSec publication on Medium. Maintained by Hackrew

Aditya Anand

Written by

CyberSec Professional | Hacker | Developer | Open Source Lover | Website - aditya12anand.com | Donate - paypal.me/aditya12anand

InfoSec Write-ups

A collection of write-ups from the best hackers in the world on topics ranging from bug bounties and CTFs to vulnhub machines, hardware challenges and real life encounters. In a nutshell, we are the largest InfoSec publication on Medium. Maintained by Hackrew

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store