Skip to content

Instantly share code, notes, and snippets.

@Porrapat
Last active January 31, 2022 07:41
Show Gist options
  • Save Porrapat/70e227758eadde3ec1a9efed1c8cecd9 to your computer and use it in GitHub Desktop.
Save Porrapat/70e227758eadde3ec1a9efed1c8cecd9 to your computer and use it in GitHub Desktop.
# ============ Login K-Bank ========================
# To Use provide your username and password
# chmod -R 777 login_k-bank.sh
# ./login_k-bank.sh
# Please provide your username and password here
# This is not the best choice to use this script. because your password is saved on your machine and transfer through script
# Please consider K-Bank Open API instead https://apiportal.kasikornbank.com/open-api/
username=
password=
# Any text file is OK.
cookie_file=login-k-bank-cookie.txt
form_to_login_url=https://online.kasikornbankgroup.com/K-Online/login.do
check_session_url=https://online.kasikornbankgroup.com/K-Online/checkSession.jsp
clear_session_url=https://online.kasikornbankgroup.com/K-Online/clearSession.jsp
redirectToIB_url=https://online.kasikornbankgroup.com/K-Online/ib/redirectToIB.jsp
security_welcome_url=https://ebank.kasikornbankgroup.com/retail/security/Welcome.do
form_statement_url=https://ebank.kasikornbankgroup.com/retail/accountinfo/AccountStatementInquiry.do
statement_url=https://ebank.kasikornbankgroup.com/retail/cashmanagement/inquiry/AccountSummary.do?action=list_domain2
summary_page_url=https://ebank.kasikornbankgroup.com/retail/cashmanagement/inquiry/AccountSummary.do?action=list_domain1
account_url=https://online.kasikornbankgroup.com/K-Online/indexHome.jsp
# Login and follow redirect to first protected page.
# get tokenId to use in Login
tokenId=$(curl -s -b "$cookie_file" -c "$cookie_file" "$form_to_login_url" | grep -oP '(?<=id="tokenId"\svalue=")[^"]*(?=")')
# Login using token id
curl -X POST -d "tokenId=$tokenId&userName=$username&password=$password&cmd=authenticate&locale=th&custType&app=0" -s -L -b $cookie_file -c $cookie_file $form_to_login_url > login.html
# get txtParam (It is K-Bank specific security)
txtParam=$(curl -X POST -s -b "$cookie_file" -c "$cookie_file" "$redirectToIB_url" | grep -oP '(?<=name="txtParam"\svalue=")[^"]*(?=")')
# post txtParam to security_welcome_url (It is K-Bank specific security)
curl -X POST -s -d "txtParam=$txtParam" -b "$cookie_file" -c "$cookie_file" "$security_welcome_url" > /dev/null
# check and clear session (It is K-Bank specific security)
curl -X POST -s -b "$cookie_file" -c "$cookie_file" "$check_session_url" > /dev/null
curl -X POST -s -b "$cookie_file" -c "$cookie_file" "$clear_session_url" > /dev/null
# curl -s -b "$cookie_file" "$account_url" > account_url.html
# now we can get any protected page you want
echo "====== Your K-Bank Summary Money (THB) is ========"
your_money=$(curl -s -b "$cookie_file" "$summary_page_url" | grep -oP '(?<=<td\sbgcolor="D1F2CB"><b>)[0-9,.]*(?=</b>)')
echo $your_money
echo "================================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment