authy-extractor
Version:
Extract 2FA tokens from Authy
70 lines (69 loc) • 3.44 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.syncAuthenticatorApps = exports.registerNewDevice = exports.createNewDeviceRequest = exports.getDeviceStatus = void 0;
const axios_1 = __importDefault(require("axios"));
const node_forge_1 = __importDefault(require("node-forge"));
const uuid_1 = require("uuid");
// RegistrationApi.prototype.getDeviceStatus
function getDeviceStatus(phoneNumber) {
return __awaiter(this, void 0, void 0, function* () {
// Authy uses Fingerprint2 library, just generate random 32 char string
// The device uuid is being used only once, hence defining it here
const deviceUUID = uuid_1.v4().split('-').join('');
const { data } = yield axios_1.default.get(`/json/users/${phoneNumber}/status`, {
params: { uuid: deviceUUID },
});
return data;
});
}
exports.getDeviceStatus = getDeviceStatus;
// RegistrationApi.prototype.createNewDeviceRequest
function createNewDeviceRequest(authyId, authMethod, deviceApp, deviceName) {
return __awaiter(this, void 0, void 0, function* () {
// CryptoHelper.generateSalt
// The signature is being used only once, hence defining it here
const signature = node_forge_1.default.util.createBuffer(node_forge_1.default.random.getBytesSync(32)).toHex();
const { data } = yield axios_1.default.post(`/json/users/${authyId}/devices/registration/start`, null, {
params: {
via: authMethod,
signature,
device_app: deviceApp,
device_name: deviceName,
},
});
return data;
});
}
exports.createNewDeviceRequest = createNewDeviceRequest;
// RegistrationApi.prototype.registerNewDevice
function registerNewDevice(authyId, pin, deviceApp, deviceName) {
return __awaiter(this, void 0, void 0, function* () {
const { data } = yield axios_1.default.post(`json/users/${authyId}/devices/registration/complete`, null, {
params: { pin, device_app: deviceApp, device_name: deviceName },
});
return data;
});
}
exports.registerNewDevice = registerNewDevice;
// AppsApi.prototype.syncAuthenticatorApps
function syncAuthenticatorApps(authyId, deviceId, otps) {
return __awaiter(this, void 0, void 0, function* () {
const { data } = yield axios_1.default.get(`/json/users/${authyId}/authenticator_tokens`, {
params: Object.assign({ apps: '', device_id: deviceId }, otps),
});
return data;
});
}
exports.syncAuthenticatorApps = syncAuthenticatorApps;