Skip to content

Commit

Permalink
Move virtual auth into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
MrYadro committed May 5, 2021
1 parent bcb4413 commit 9e7e9a1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 60 deletions.
29 changes: 29 additions & 0 deletions modecxr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"log"
Expand Down Expand Up @@ -65,3 +67,30 @@ func (sc syscon) receiveCXRCommand() (string, error) {
}
return "", errors.New("wrong response code")
}

func (sc syscon) virtualCommandCXRAuth() string {
res, err := sc.proccessCommand("AUTH1 " + auth)
resHex, _ := hex.DecodeString(res)
if err == nil && bytes.Equal(resHex[0:0x10], auth1ResponseHeader) {
fmt.Println("Right Auth1 response header")
data := decode(resHex[0x10:0x40])
if bytes.Equal(data[0x8:0x10], zero[0x0:0x8]) && bytes.Equal(data[0x10:0x20], auth1Response) && bytes.Equal(data[0x20:0x30], zero) {
fmt.Println("Right Auth1 response body")
newData := append(data[0x8:0x10], data[0x0:0x8]...)
newData = append(newData, zero...)
newData = append(newData, zero...)
auth2Body := encode(newData)
authBody := append(auth2RequestHeader, auth2Body...)
com := fmt.Sprintf("AUTH2 %02X", authBody)
_, err := sc.proccessCommand(com)
if err == nil {
return "Auth successful"
}
} else {
fmt.Println("Wrong Auth1 response body")
}
} else {
fmt.Println("Wrong Auth1 response header")
}
return "Auth failed"
}
40 changes: 40 additions & 0 deletions modecxrf.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"log"
Expand Down Expand Up @@ -31,3 +33,41 @@ func (sc syscon) receiveCXRFCommand() (string, error) {
}
return "", errors.New("wrong response")
}

func (sc syscon) virtualCommandCXRFAuth() string {
res, err := sc.proccessCommand("scopen")
if err == nil && res == "SC_READY" {
fmt.Printf("Successfully opened syscon\n%s\n", res)
res, err = sc.proccessCommand(auth)
if err == nil && len(res) == 128 {
fmt.Println("Right response length")
resHex, _ := hex.DecodeString(res)
if bytes.Equal(resHex[0:0x10], auth1ResponseHeader) {
fmt.Println("Right Auth1 response header")
data := decode(resHex[0x10:0x40])
if bytes.Equal(data[0x8:0x10], zero[0x0:0x8]) && bytes.Equal(data[0x10:0x20], auth1Response) && bytes.Equal(data[0x20:0x30], zero) {
fmt.Println("Right Auth1 response body")
newData := append(data[0x8:0x10], data[0x0:0x8]...)
newData = append(newData, zero...)
newData = append(newData, zero...)
auth2Body := encode(newData)
authBody := append(auth2RequestHeader, auth2Body...)
com := fmt.Sprintf("%02X", authBody)
res, err := sc.proccessCommand(com)
if err == nil && strings.Contains(res, "SC_SUCCESS") {
return "Auth successful"
}
} else {
fmt.Println("Wrong Auth1 response body")
}
} else {
fmt.Println("Wrong Auth1 response header")
}
} else {
fmt.Println("Wrong response length")
}
} else {
fmt.Println("Error opening syscon")
}
return "Auth failed"
}
62 changes: 2 additions & 60 deletions virtualcommand.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/hex"
Expand Down Expand Up @@ -167,67 +166,10 @@ func encode(plaintext []byte) []byte {
func (sc syscon) virtualCommandAuth() string {
switch sc.mode {
case "cxrf":
res, err := sc.proccessCommand("scopen")
if err == nil && res == "SC_READY" {
fmt.Printf("Successfully opened syscon\n%s\n", res)
res, err = sc.proccessCommand(auth)
if err == nil && len(res) == 128 {
fmt.Println("Right response length")
resHex, _ := hex.DecodeString(res)
if bytes.Equal(resHex[0:0x10], auth1ResponseHeader) {
fmt.Println("Right Auth1 response header")
data := decode(resHex[0x10:0x40])
if bytes.Equal(data[0x8:0x10], zero[0x0:0x8]) && bytes.Equal(data[0x10:0x20], auth1Response) && bytes.Equal(data[0x20:0x30], zero) {
fmt.Println("Right Auth1 response body")
newData := append(data[0x8:0x10], data[0x0:0x8]...)
newData = append(newData, zero...)
newData = append(newData, zero...)
auth2Body := encode(newData)
authBody := append(auth2RequestHeader, auth2Body...)
com := fmt.Sprintf("%02X", authBody)
res, err := sc.proccessCommand(com)
if err == nil && strings.Contains(res, "SC_SUCCESS") {
return "Auth successful"
}
} else {
fmt.Println("Wrong Auth1 response body")
}
} else {
fmt.Println("Wrong Auth1 response header")
}
} else {
fmt.Println("Wrong response length")
}
} else {
fmt.Println("Error opening syscon")
}
return sc.virtualCommandCXRFAuth()
default:
res, err := sc.proccessCommand("AUTH1 " + auth)
resHex, _ := hex.DecodeString(res)
if err == nil && bytes.Equal(resHex[0:0x10], auth1ResponseHeader) {
fmt.Println("Right Auth1 response header")
data := decode(resHex[0x10:0x40])
if bytes.Equal(data[0x8:0x10], zero[0x0:0x8]) && bytes.Equal(data[0x10:0x20], auth1Response) && bytes.Equal(data[0x20:0x30], zero) {
fmt.Println("Right Auth1 response body")
newData := append(data[0x8:0x10], data[0x0:0x8]...)
newData = append(newData, zero...)
newData = append(newData, zero...)
auth2Body := encode(newData)
authBody := append(auth2RequestHeader, auth2Body...)
com := fmt.Sprintf("AUTH2 %02X", authBody)
res, err := sc.proccessCommand(com)
fmt.Println(res)
if err == nil {
return "Auth successful"
}
} else {
fmt.Println("Wrong Auth1 response body")
}
} else {
fmt.Println("Wrong Auth1 response header")
}
return sc.virtualCommandCXRAuth()
}
return "Auth failed"
}

func parseErrorCode(err string) string {
Expand Down

0 comments on commit 9e7e9a1

Please sign in to comment.