Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please help me create a login script with bash #12

Open
hillz2 opened this issue Feb 25, 2022 · 0 comments
Open

Please help me create a login script with bash #12

hillz2 opened this issue Feb 25, 2022 · 0 comments

Comments

@hillz2
Copy link

hillz2 commented Feb 25, 2022

Hi, I'm trying to recreate your script with bash but I got stuck at the login part, I keep getting:

<?xml version="1.0" encoding="UTF-8"?>
<error>
<code>100006</code>
<message></message>
</error>

Based on the error code, it's ERROR_PARAMETER_ERROR = 100006
Here's my script:

#!/bin/bash

username="admin"
password="admin"

E5577_auth() {
	curl -sc '/tmp/E5577' 'http://192.168.8.1/html/home.html' > /dev/null
	cookie=$(curl -sb /tmp/E5577 http://192.168.8.1/api/webserver/SesTokInfo | awk -F "[><]" '/SesInfo/ {print $3}')
	token=$(curl -sb /tmp/E5577 http://192.168.8.1/api/webserver/SesTokInfo | awk -F "[><]" '/TokInfo/ {print $3}')
	echo "Cookie: $cookie"
	echo "Token: $token"
	if [[ -z "$cookie" ]] || [[ -z "$token" ]]; then
		echo "Authentication failed."
	fi
}
login() {
	E5577_auth
	password=$(echo -n "$password" | sha256sum | cut -d ' ' -f 1 | sed ':a;N;$!ba;s/\n//g') # 1. Original password is hashed first
	password=$(echo -n "$password" | base64 | sed ':a;N;$!ba;s/\n//g') # 2. Then the hashed password is encoded with base64
	password=$(echo -n "$username$password$token"  | sed ':a;N;$!ba;s/\n//g') # 3. Append both username & token
	password=$(echo -n "$password" | sha256sum | cut -d ' ' -f 1 | sed ':a;N;$!ba;s/\n//g') # 4. hash again
	password=$(echo -n "$password" | base64 | sed ':a;N;$!ba;s/\n//g') # 5. encode again
	echo "Password: $password"
	data="<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><Username>$username</Username><password_type>4</password_type><Password>$password</Password></request>"
	curl -s 'http://192.168.8.1/api/user/login' -H "Cookie: $cookie" -H "__RequestVerificationToken: $token" --data "$data"
}
login

Can you help me fix it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant