Skip to content

Please help me create a login script with bash #12

@hillz2

Description

@hillz2

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions