Skip to content

Instantly share code, notes, and snippets.

@alechash
Created September 7, 2021 21:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alechash/f54e68f71f33838ecc2fbdf658323abc to your computer and use it in GitHub Desktop.
Save alechash/f54e68f71f33838ecc2fbdf658323abc to your computer and use it in GitHub Desktop.
a javascript snippet to automatically run your AM4 game
const fetch = require('node-fetch');
const jsdom = require("jsdom");
const {
JSDOM
} = jsdom;
//
// Twilio settings.
// These are used to send texts.
// You can find these credentials on your Twilio account.
// Note though, the free trials of Twilio includes $15 in SMS credits for free.
//
// Twilio Account SID
var accountSid;
var authToken;
var messageServiceId;
var client;
// #################################################### //
//
// Settings //
//
const am4SessId = ''; // AM4 Session ID. What logs you into AM4. Replace this with your AM4 Sess ID. See the `instructions.md#sess-id` file for instructions on this.
//
const sendTexts = true; // Will send text updates if set to true.
const departFlights = true; // Will automatically depart flights if flighs need departed.
const doMaint = true; // Will perform maintenance if anything is above thresholds below.
//
const buyFuelPrice = 800; // Will buy fuel if price is less than this.
const buyCO2Price = 140; // Will buy CO2 if price is less than this.
//
const repairThreshold = 30; // Percontage of wear on an aircraft to automatically start maintenance.
const aCheckThreshold = 25; // Hours til A-Check. If less than, automatically starts an A-Check, if possible.
//
const yourPhoneNumber = '+1' // your phone number to send text updates to.
//
// #################################################### //
if (sendTexts) {
accountSid = '';
authToken = '';
messageServiceId = '';
client = require('twilio')(accountSid, authToken);
};
const update = (message) => {
return console.log(`\n[UPDATE] :: ${message}`);
};
/**
* Departs all flights automatically.
*/
const checkFlights = (data) => {
fetch(`https://www.airline4.net/route_depart.php?mode=all&ids=x&rand=${Math.random()}`, {
headers: {
'cookie': `PHPSESSID=${am4SessId}`
}
});
update('Flights departed. Checking again in 10 minutes.');
};
/**
* Checks maintenance schedules.
* If maintenance is needed, it is scheduled.
*/
const performMaintenance = () => {
fetch(`https://www.airline4.net/maint_plan_do.php?type=bulkRepair&id=12722621&mode=do&pct=${repairThreshold}&rand=${Math.random()}`, {
headers: {
'cookie': `PHPSESSID=${am4SessId}`
}
});
update('Maintenance scheduled.');
};
/**
* Checks fuel fuel prices.
* If fuel is below threshold, buy it.
* If texts enabled, send a text.
*/
const checkFuel = (data) => {
fetch(`https://www.airline4.net/fuel.php?undefined&fbSig=false&_=1630201072632&rand=${Math.random()}`, {
headers: {
'cookie': `PHPSESSID=${am4SessId}`
}
})
.then(res => res.text())
.then(text => {
const dom = new JSDOM(text);
var text = '';
var fuelPrice = dom.window.document.querySelector("#sumCost").textContent;
var fuelAmountToBuy = dom.window.document.querySelector("#remCapacity").textContent;
update(`Fuel is $${fuelPrice}`);
if (Number(fuelPrice) <= buyFuelPrice) {
fetch(`https://www.airline4.net/fuel.php?mode=do&amount=${fuelAmountToBuy.replace(/,/g, '')}&rand=${Math.random()}`, {
headers: {
'cookie': `PHPSESSID=${am4SessId}`
}
});
update(`Bought ${fuelAmountToBuy} pounds of fuel.`);
text = `Fuel is $${fuelPrice}. That is below the $${buyFuelPrice + 1} threshold. I have filled your tanks. I bought ${fuelAmountToBuy} pounds of fuel.`;
if (sendTexts) {
client.messages
.create({
body: text,
messagingServiceSid: messageServiceId,
to: yourPhoneNumber
})
.then(message => console.log(message.sid))
.done();
};
};
});
};
const checkCo2 = (data) => {
fetch(`https://www.airline4.net/co2.php?undefined&fbSig=false&_=1630201072632&rand=${Math.random()}`, {
headers: {
'cookie': `PHPSESSID=${am4SessId}`
}
})
.then(res => res.text())
.then(text => {
const dom = new JSDOM(text);
var text = '';
var co2Price = dom.window.document.querySelector("#sumCost").textContent;
var co2AmountToBuy = dom.window.document.querySelector("#remCapacity").textContent;
update(`CO2 is $${co2Price}`);
if (Number(co2Price) <= buyCO2Price) {
fetch(`https://www.airline4.net/co2.php?mode=do&amount=${co2AmountToBuy.replace(/,/g, '')}&rand=${Math.random()}`, {
headers: {
'cookie': `PHPSESSID=${am4SessId}`
}
});
update(`Bought ${co2AmountToBuy} pounds of fuel.`);
text = `CO2 is $${co2Price}. That is below the $${buyCO2Price + 1} threshold. I have filled your tanks. I bought ${co2AmountToBuy} quotas of CO2.`;
if (sendTexts) {
client.messages
.create({
body: text,
messagingServiceSid: messageServiceId,
to: yourPhoneNumber
})
.then(message => update('Text sent. ' + message.sid))
.done();
};
};
});
};
const runGame = () => {
setInterval(function() {
checkFuel();
checkCo2();
}, 1800000);
setInterval(function() {
checkFlights();
performMaintenance();
}, 600000);
};
runGame();
checkFlights();
performMaintenance();
checkFuel();
checkCo2();
//fetch('https://www.airline4.net/maint_plan_do.php?mode=do&type=repair&id=12482884&rand=' + Math.random(), {
// headers: {
// 'cookie': 'PHPSESSID='
// }
//})

Instructions

This script automatically runs and manages your AM4 account.

Prerequisites

  • NodeJS
  • NPM (should install with NodeJS so no need to manually install)

Setup

  1. Download this code.
  2. Create a folder and move the JS file to it.
  3. CD to the folder in terminal: cd <folder_name>
  4. Initialize Node project: npm init -y
  5. Please follow the ## SESS ID instructions.
  6. run npm i jsdom twilio node-fetch
  7. Once CDed into the folder run node AM4.js

SESS ID

For this step you will need to have BurpSuite community edition installed and running on your computer. Make sure your phone and computer are on the same network (2.4 or 5 does not matter).

Setting Up BurpSuite CE

  1. Open a new empty BurpSuite project
  2. Click the "Proxy" tab, then the "Options" tab
  3. Under "Proxy Listeners" select the only item and press the "Edit" button
  4. Under the "Binding" then "Bind to address" section, select "All interfaces"
  5. Press "Ok" to save the settings

Setting up iPhone proxy

I only have instructions for iPhone at the moment. You can do this on Android too but you'll have to figure it out yourself.

  1. Open "Settings" app then "WiFi" then press the "i" icon next to your connected network
    • Make sure you are on the same network as your computer.
  2. Scroll to the bottom and select "Configure Proxy"
  3. Select the "Manual" option
  4. For the server, input your computers local IP Address. This can be found in your computer settings. It should look like "192.168.x.x"
  5. For the port, put 8080, or if you changed it in BurpSuite settings, put that port.
  6. Open safari and navigate to http://burp
  7. Press the "Download Certificate" button and allow the install
  8. Open settings app again and navigate "General" > "VPN & Device Management" > "PortSwigger CA" and install it.
  9. Go back to "General" settings then > "About" > "Certificate Trust Settings" (at the bottom) > and enable "PortSwigger CA"

You should now be able to make requests and intercept them on your computer.

Finding Session ID

  1. Open the AM4 after setting up the proxy and press any tab, like the settings or fuel popup
  2. Open BurpSuite again then "Proxy" then "HTTP History"
  3. Find a request made to "am4.pagespeedster.com"
  4. Press and inspect the request until you see the cookies. Find the "PHPSESSID" cookie, that is your AM4 session ID.
  5. Lastly, go to line 24 of the JS file and fill the string with your session ID.
  6. Finally, go back to step six of ## Setup

Text Message Updates

This step is completely optional. You do not need to follow this step if you don't want.

  1. Signup for Twilio
  2. Get a phone number and create a messaging service for that phone number.
  3. Go to lines 40, 41, and 42 and input the credentials.
  4. Go to line 35 and input your phone number. Make sure to include + and country code!
  5. Restart the server
@limgarcia
Copy link

I replaced the run game const with these 2 functions

function fuelUp(){ update(Fuel up at: ${Date()}`);
checkFuel();
checkCo2();
setTimeout(fuelUp,1800000)
}

function runnerUp() {
update(Takeoff at: ${Date()});
checkFlights();
checkFuel();
checkCo2();
performMaintenance();
setTimeout(runnerUp,300000+420000*Math.random())
}

//runGame();
fuelUp();
runnerUp();
//checkFlights();
//performMaintenance();
//checkFuel();
//checkCo2();`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment