Created
          January 11, 2017 06:02 
        
      - 
      
- 
        Save comigor/37b76557a50cfad11504873f08a07918 to your computer and use it in GitHub Desktop. 
    intermedium.sh
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| cookies="$HOME/.intermediumcookies" | |
| rm $cookies | |
| headers_first="--cookie $cookies --cookie-jar $cookies -s -H 'Pragma: no-cache' -H 'DNT: 1' -H 'Accept-Encoding: gzip, deflate, sdch, br' -H 'Accept-Language: en-US,en;q=0.8' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive'" | |
| headers_second="--cookie $cookies --cookie-jar $cookies -s -H 'Pragma: no-cache' -H 'Origin: https://internetbanking.intermedium.com.br' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.8' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: no-cache' -H 'Referer: https://internetbanking.intermedium.com.br/login.jsf' -H 'Connection: keep-alive' -H 'DNT: 1'" | |
| headers_login="--cookie $cookies --cookie-jar $cookies -s -H 'Pragma: no-cache' -H 'Origin: https://internetbanking.intermedium.com.br' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36' -H 'Content-type: application/x-www-form-urlencoded;charset=UTF-8' -H 'Accept: */*' -H 'Faces-Request: partial/ajax' -H 'Cache-Control: no-cache' -H 'Referer: https://internetbanking.intermedium.com.br/login.jsf' -H 'Connection: keep-alive' -H 'DNT: 1'" | |
| headers_redirect="--cookie $cookies --cookie-jar $cookies -s -H 'Pragma: no-cache' -H 'DNT: 1' -H 'Accept-Encoding: gzip, deflate, sdch, br' -H 'Accept-Language: en-US,en;q=0.8' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: no-cache' -H 'Referer: https://internetbanking.intermedium.com.br/login.jsf' -H 'Connection: keep-alive'" | |
| headers_conta="--cookie $cookies --cookie-jar $cookies -s -H 'Pragma: no-cache' -H 'Origin: https://internetbanking.intermedium.com.br' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36' -H 'Content-type: application/x-www-form-urlencoded;charset=UTF-8' -H 'Accept: */*' -H 'Faces-Request: partial/ajax' -H 'Cache-Control: no-cache' -H 'Referer: https://internetbanking.intermedium.com.br/comum/home.jsf' -H 'Connection: keep-alive' -H 'DNT: 1'" | |
| function get_viewstate() { | |
| # viewstate=$(echo "$html" | grep -m 1 'name="javax.faces.ViewState"' \ | |
| # | sed -e 's/^.*name="javax.faces.ViewState"[^>]*value="//' \ | |
| # | sed -e 's/".*//') | |
| viewstate=$(echo $html | LC_ALL=C awk 'match($0, /name="javax.faces.ViewState"[^>]*value="([^"]+)"/, ary) {print ary[1]}' | sed -e 's/ .*//') | |
| } | |
| # echo "Contacting Intermedium 1/2..." | |
| html=$(curl $headers_first https://internetbanking.intermedium.com.br/login.jsf) | |
| get_viewstate | |
| # echo "Contacting Intermedium 2/2..." | |
| html=$(curl $headers_second https://internetbanking.intermedium.com.br/login.jsf --data "frmLogin=frmLogin&javax.faces.ViewState=${viewstate/:/%3A}&j_idt42=CLIENTE_RENDA_FIXA&login=$login&j_idt54=Aguarde...") | |
| get_viewstate | |
| # echo "Logging-in..." | |
| declare -a arr=("frmLogin=frmLogin&javax.faces.ViewState=${viewstate/:/%3A}&j_idt42=CLIENTE_RENDA_FIXA&login=$login&javax.faces.source=j_idt154&javax.faces.partial.event=click&javax.faces.partial.execute=j_idt154%20panelGeral&javax.faces.partial.render=panelGeral&javax.faces.behavior.event=action&javax.faces.partial.ajax=true" | |
| ... | |
| "frmLogin=frmLogin&javax.faces.ViewState=${viewstate/:/%3A}&j_idt42=CLIENTE_RENDA_FIXA&login=$login&javax.faces.source=j_idt79&javax.faces.partial.event=click&javax.faces.partial.execute=j_idt79%20j_idt79&javax.faces.partial.render=frmLogin&javax.faces.behavior.event=action&javax.faces.partial.ajax=true" | |
| ) | |
| for i in "${arr[@]}"; do | |
| # -L -s -o /dev/null | |
| curl $headers_login https://internetbanking.intermedium.com.br/login.jsf --data "$i" > /dev/null | |
| done | |
| # echo "Opening conta..." | |
| html=$(curl $headers_redirect https://internetbanking.intermedium.com.br/comum/home.jsf) | |
| get_viewstate | |
| html=$(curl $headers_conta https://internetbanking.intermedium.com.br/comum/home.jsf --data "frmSaldos=frmSaldos&javax.faces.ViewState=${viewstate/:/%3A}&javax.faces.source=j_idt167&javax.faces.partial.event=click&javax.faces.partial.execute=j_idt167%20j_idt167&javax.faces.partial.render=frmSaldos&javax.faces.behavior.event=action&javax.faces.partial.ajax=true") | |
| html=$(curl $headers_conta https://internetbanking.intermedium.com.br/comum/home.jsf --data "frmSaldos=frmSaldos&javax.faces.ViewState=${viewstate/:/%3A}&javax.faces.source=j_idt209&javax.faces.partial.event=click&javax.faces.partial.execute=j_idt209%20j_idt209&javax.faces.partial.render=frmSaldos&javax.faces.behavior.event=action&javax.faces.partial.ajax=true") | |
| conta_corrente=$(echo $html | LC_ALL=C awk 'match($0, /spanValores.{0,50}R\$ ([^<]+)/, ary) {print ary[1]}' | sed -e 's/\.//' | sed -e 's/,/./') | |
| investimentos=$(echo $html | LC_ALL=C awk 'match($0, /totalResultados.{0,50}R\$ ([^<]+)/, ary) {print ary[1]}' | sed -e 's/\.//' | sed -e 's/,/./') | |
| echo "Total balance: R$" $(echo "$conta_corrente+$investimentos" | bc) | |
| # TODO: mapear teclado virtual: | |
| # --data "frmLogin=frmLogin&javax.faces.ViewState=-5897667852635172161%3A8784923107746938399&j_idt42=CLIENTE_RENDA_FIXA&login=$login&javax.faces.source=j_idt87%3A0%3Aj_idt88&javax.faces.partial.event=click&javax.faces.partial.execute=j_idt87%3A0%3Aj_idt88%20j_idt87%3A0%3Aj_idt88&javax.faces.partial.render=panelTeclado&javax.faces.behavior.event=action&javax.faces.partial.ajax=true" | |
| # --data "javax.faces.source=$BLAH&javax.faces.partial.event=click&javax.faces.partial.execute=$BLAH%20$BLAH" | |
| # | |
| # 1234567890qwertyuiopasdfghjklçzxcvbnm | |
| # j_idt87%3A0%3Aj_idt88 | |
| # j_idt87%3A1%3Aj_idt88 | |
| # j_idt87%3A2%3Aj_idt88 | |
| # j_idt87%3A3%3Aj_idt88 | |
| # j_idt87%3A4%3Aj_idt88 | |
| # j_idt87%3A5%3Aj_idt88 | |
| # j_idt87%3A6%3Aj_idt88 | |
| # j_idt87%3A7%3Aj_idt88 | |
| # j_idt87%3A8%3Aj_idt88 | |
| # j_idt87%3A9%3Aj_idt88 | |
| # j_idt94%3A0%3Aj_idt96 | |
| # j_idt94%3A1%3Aj_idt96 | |
| # j_idt94%3A2%3Aj_idt96 | |
| # j_idt94%3A3%3Aj_idt96 | |
| # j_idt94%3A4%3Aj_idt96 | |
| # j_idt94%3A5%3Aj_idt96 | |
| # j_idt94%3A6%3Aj_idt96 | |
| # j_idt94%3A7%3Aj_idt96 | |
| # j_idt94%3A8%3Aj_idt96 | |
| # j_idt94%3A9%3Aj_idt96 | |
| # j_idt100%3A0%3Aj_idt102 | |
| # j_idt100%3A1%3Aj_idt102 | |
| # j_idt100%3A2%3Aj_idt102 | |
| # j_idt100%3A3%3Aj_idt102 | |
| # j_idt100%3A4%3Aj_idt102 | |
| # j_idt100%3A5%3Aj_idt102 | |
| # j_idt100%3A6%3Aj_idt102 | |
| # j_idt100%3A7%3Aj_idt102 | |
| # j_idt100%3A8%3Aj_idt102 | |
| # j_idt100%3A9%3Aj_idt102 | |
| # j_idt104%3A1%3Aj_idt105 | |
| # j_idt104%3A2%3Aj_idt105 | |
| # j_idt104%3A3%3Aj_idt105 | |
| # j_idt104%3A4%3Aj_idt105 | |
| # j_idt104%3A5%3Aj_idt105 | |
| # j_idt104%3A6%3Aj_idt105 | |
| # j_idt104%3A7%3Aj_idt105 | |
| # j_idt109%3A0%3Aj_idt111 | |
| # | |
| # SHIFT + Q | |
| # j_idt104%3A8%3Aj_idt106 | |
| # j_idt94%3A0%3Aj_idt96 | |
| # | |
| # shift + q | |
| # j_idt104%3A8%3Aj_idt106 | |
| # j_idt94%3A0%3Aj_idt96 | |
| # | |
| # special | |
| # j_idt109%3A1%3Aj_idt113 | |
| # | |
| # -/:;()$&@[]{}#%^*+_\|~<>€£¥.,?!'"= | |
| # j_idt120%3A0%3Aj_idt121 | |
| # j_idt120%3A1%3Aj_idt121 | |
| # j_idt120%3A2%3Aj_idt121 | |
| # j_idt120%3A3%3Aj_idt121 | |
| # j_idt120%3A4%3Aj_idt121 | |
| # j_idt120%3A5%3Aj_idt121 | |
| # j_idt120%3A6%3Aj_idt121 | |
| # j_idt120%3A7%3Aj_idt121 | |
| # j_idt120%3A8%3Aj_idt121 | |
| # j_idt125%3A0%3Aj_idt126 | |
| # j_idt125%3A1%3Aj_idt126 | |
| # j_idt125%3A2%3Aj_idt126 | |
| # j_idt125%3A3%3Aj_idt126 | |
| # j_idt125%3A4%3Aj_idt126 | |
| # j_idt125%3A5%3Aj_idt126 | |
| # j_idt125%3A6%3Aj_idt126 | |
| # j_idt125%3A7%3Aj_idt126 | |
| # j_idt125%3A8%3Aj_idt126 | |
| # j_idt129%3A0%3Aj_idt130 | |
| # j_idt129%3A1%3Aj_idt130 | |
| # j_idt129%3A2%3Aj_idt130 | |
| # j_idt129%3A4%3Aj_idt130 | |
| # j_idt129%3A5%3Aj_idt130 | |
| # j_idt129%3A6%3Aj_idt130 | |
| # j_idt129%3A7%3Aj_idt130 | |
| # j_idt129%3A8%3Aj_idt130 | |
| # j_idt132%3A0%3Aj_idt133 | |
| # j_idt132%3A1%3Aj_idt133 | |
| # j_idt132%3A2%3Aj_idt133 | |
| # j_idt132%3A3%3Aj_idt133 | |
| # j_idt132%3A4%3Aj_idt133 | |
| # j_idt132%3A5%3Aj_idt133 | |
| # j_idt132%3A6%3Aj_idt133 | |
| # | |
| # abc | |
| # j_idt132%3A7%3Aj_idt133 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment