Skip to content

Instantly share code, notes, and snippets.

@picatz
Created February 10, 2018 01:45
Show Gist options
  • Save picatz/8f2fdfe6ab011f7fa1af045f517b81e3 to your computer and use it in GitHub Desktop.
Save picatz/8f2fdfe6ab011f7fa1af045f517b81e3 to your computer and use it in GitHub Desktop.
example client-side javascript code to communicate with bettercap API
var session
var credentials
var resp
function encodeBasicAuthorizationCredentials(options = {}) {
return 'Basic ' + btoa(options.username + ":" + options.password)
}
function setCredentials(options = {}) {
credentials = encodeBasicAuthorizationCredentials(options)
}
function getSession() {
fetch("/api/session", { method: 'GET', headers: { 'Authorization': credentials } })
.then(function(response) {
response.json().then(function(json) { session = json })
});
}
function setSession(data) {
var request = new Request("/api/session", {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Authorization': credentials
}
});
fetch(request).then(function(response) {
response.json().then(function(json) { resp = json })
});
}
setCredentials({ username: "bcap", password: "bcap" })
data = {"cmd":"net.probe on"}
setSession(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment