Category Archives: Random

Random stuff I’ve managed to break

AWS Installing AWS Inspector Agent on Windows EC2 Instance

Hi everyone,

Just a quick post on installing the AWS Inspector Agent on a Windows EC2 instance.

Open PowerShell and run the following command:

(new-object System.Net.WebClient).DownloadFile('https://inspector-agent.amazonaws.com/windows/installer/latest/AWSAgentInstall.exe','C:\Users\Administrator\Desktop\AWSAgentInstall.exe')

On your desktop, right click on AWSAgentInstall.exe and select run as administrator. Follow the prompts.

Go to run, and execute services.msc. You should now see the Amazon SSM Agent:

If you go to your amazon console > amazon inspector > assessment targets > Click on your relevant target > Preview Target:

Your agent status should now be healthy.

Thanks to these links for the info:
https://superuser.com/a/330754/124014
https://docs.aws.amazon.com/inspector/latest/userguide/inspector_installing-uninstalling-agents.html#install-windows

Dynamic Robots.txt with Web Api 2

Hi everyone,

For a project I’m currently working on I needed a dynamic robots.txt. Because our test environment is public facing we want to keep it from being indexed by Google etc. It took a bit of Googling to find a solution that worked, but in the end it was actually pretty simple.

Here’s the action in one of the API Controllers:

    public class UtilitiesController : CustomBaseApiController
    {
        [Route("Robots.txt")]
        [HttpGet]
        public HttpResponseMessage GetRobotsFile()
        {
            var resp = new HttpResponseMessage(HttpStatusCode.OK);
            var stringBuilder = new StringBuilder();
 
            if (Helpers.IsProduction())
            {
                // Allow bots in production
                stringBuilder.AppendLine("user-agent: *");
                stringBuilder.AppendLine("disallow: ");
            }
            else
            {
                // Don't allow bots in non-production environments
                stringBuilder.AppendLine("user-agent: *");
                stringBuilder.AppendLine("disallow: *");
            }
 
            resp.Content = new StringContent(stringBuilder.ToString());
 
            return resp;
        }
    }

Also need to add the following to your web.config so that the robots.txt file can processed by the routing handler. Without this IIS will attempt to serve it as a static file and will return a 404 when it’s not found:

<system.webServer>
    <modules>
    <!-- ... -->
        <handlers>
        <add name="RobotsTxt" path="robots.txt" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        <!-- Other handlers -->
    </modules>
    <!-- ... -->
</system.webServer>

In production you’ll end up with the following:

user-agent: *
disallow:

And any other environments:

user-agent: *
disallow: *

Thanks to these answers on stackoverflow for the info:
https://stackoverflow.com/a/52270877/522859
https://stackoverflow.com/a/17037935/522859

Adding a Link to a Drawer – Material UI and ReactJS

Hi everyone,

I ran into a bit of an issue turning a menuitem into a link with Material UI and React-Router. The main problems being that underlines appeared and threw the spacing out.

To summarize, use the component attribute on the ListItem:

<List>
   <ListItem button component={Link} to="https://www.whatibroke.com">
        <ListItemText primary="WhatIBroke" />
   </ListItem>
</List>

The official docs cover it here: https://material-ui.com/api/list-item/

See the following stackoverflow post for more info: https://stackoverflow.com/a/50558139/522859

Remote Desktop: An authentication error has occurred. – This could be due to CredSSP encryption oracle remediation.

Hi everyone,

I ran into an auth issue with remote desktop today:

An authentication error has occurred.
The function requested is not supported.
Remote computer: XXXX

This could be due to CredSSP encryption oracle remediation.
For more information, see hhtps://go.microsoft.com/fwlink/?linkid=866660

The solution is to add the May 2018 Windows Security Update on both the remote and local machines. If that’s not possible a registry entry can be added to the local machine to circumvent the issue. This can be done by running the following command in a command prompt as administrator:

REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\CredSSP\Parameters\ /v AllowEncryptionOracle /t REG_DWORD /d 2

You can also add the entry manually via regedit.

The cause is actually because of a security update in windows. If either the remote or local machine has the update and the other does not the error is triggered. There’s more info available on the following page: https://github.com/stascorp/rdpwrap/issues/480

Using INA219 (GY-219) with the Raspberry Pi

Hi everyone,

I’ve just setup an INA219B Voltage/Current sensor on my RaspberryPi. Just thought I’d link the tutorials and libraries I used – there’s a lot of really useful info out there.

Install the following library via git: https://github.com/chrisb2/pi_ina219
sudo pip3 install pi-ina219

Follow this tutorial: https://www.rototron.info/raspberry-pi-ina219-tutorial/

Misc Notes

  • Common ground is required
  • Vin – and Vin+ are attached to +, neither goes to ground

Custom Sensor Address
na = INA219(SHUNT_OHMS, MAX_EXPECTED_AMPS, address=0x41)

Can be configured via the following:

https://www.rototron.info/raspberry-pi-ina219-tutorial/

https://www.rototron.info/raspberry-pi-ina219-tutorial/

Enable Low Power Between Reads
ina.configure(ina.RANGE_16V)
while True:
print "Voltage : %.3f V" % ina.voltage()
ina.sleep()
time.sleep(60)
ina.wake()

If you’re getting the following error:

OSError: [Errno 121] Remote I/O error

Run the following command:

i2cdetect -y 1

And check to ensure that your device is showing up on 40. If it’s a different number you’ll just need to update the address in your code e.g. (0x40, 0x41, etc.)

wget or curl on Windows

Hey everyone,

Just a quick post on a Window’s equivalent to wget/curl.

To start, you’ll need to open PowerShell (run > powershell.exe). To retrieve the page, you’ll just need to enter the following one liner:

(new-object System.Net.WebClient).DownloadFile('http://www.whatibroke.com','C:\my_output_file.txt')

The page contents will be stored in the output file provided as the second parameter to DownloadFile. To view it, just open the file in a text editor.

If you’d rather something with a GUI, winwget has been recommended on SuperUser.

Australian Tax File Number Generator (TFN)

Hey everyone,

I came across an old VB Script used to generate random TFNs for testing. I’ve just done up a quick JavaScript bookmarklet to replace it. Just drag the link below to your bookmarks bar and you’ll be able to generate random TFNs.

Click to Generate (or drag to your bookmarks bar): TFN Generator

A bookmarklet to generate random TFNs

A bookmarklet to generate random TFNs

For info on how it all works, checkout the Wikipedia page: Australian Tax File Number

Sample Australian Tax File Numbers/Test Australian Tax File Numbers:
865414088
459599230
112474082
565051603
907974668

UPDATE:
If you’re using IE, right click on the link and press add to favourites. Once you’ve added it, click the link in your favourites sidebar. The generator will appear in the top right hand corner of the page.

Let me know if you have any trouble. If you’d like to a custom or corporate copy please contact me.

Coinroll.it Betting Bot – Martingale System

Hey everyone,

I received an odd request for a script the other day – a bot for an bitcoin gambling website. The request was for a simple JavaScript bookmarklet that would execute the martingale betting system autonomously.

The code I ended up with as follows:

  1. javascript: /* MANUAL CONFIGURATION - Initialisation Only */ var reset_to = 0.00001; /* Amount to reset to */ /* Initialise bot */ initialise_bookmarklet(); var previous_bet = null; var bot_running = false; create_message('Bot initialised, hit run to start...'); /* Runs the bot */ function run_bot(){ /* Check to see whether bot needs to be run/stopped */ if(bot_running == true){ /* Create vars */ var bet_amount = $("#betamount").val(); var parent_id = $('#bets .item:first').attr('id'); var result = $('#bets .item:first-child .lucky'); /* Check if result is same as previous */ if(result == null || result.length == 0){ create_message('No bets on screen... waiting for next run.'); } else if(parent_id != previous_bet){ /* Set previous bet to current bet */ previous_bet = parent_id; /* Check the current bet amount */ if(bet_amount >= $('#max_bet').data('max_bet') || bet_amount > $('#account-balance').text()){ /* Reset bet amount */ $('#betamount').val(reset_to); create_message('<span style="font-weight:bold;color:red;">MAXXED OUT</span>'); } /* Check if first item is a win */ if($(result).hasClass('win')){ /* Adjust bet amount to reset amount and roll */ $('#betamount').val(reset_to); roll(); } else if($(result).hasClass('lose')){ /* Double amount and roll again */ setDouble(); roll(); } else{ create_message('Unknown status, not a win or loss... wait for next run...'); } } else if ($('#betbutton').hasClass('pressed') == false){ create_message('Assumed 503, press again...'); roll(); } else{ create_message('Previous bet is still there, wait ' + $('#bot_timeout').val() + 'ms...'); } /* Schedule next run */ setTimeout(function(){ run_bot(); }, $('#bot_timeout').val()); } else if(bot_running == false){ /* Update status to prevent bot running again */ create_message('Bot stopped...'); } else{ /* Error occurred */ create_message('Error: Unknown status.'); create_message('Bot stopped...'); } } /* Run when button clicked */ function bot_status_change(button){ /* Check whether to start or stop bot */ if(bot_running == false){ /* Run bot and display message */ create_message('Running bot...'); $(button).text('Pause'); bot_running = true; run_bot(); } else if(bot_running == true){ /* Update status to prevent bot running again */ create_message('Stopping bot...'); bot_running = false; $(button).text('Run'); } else{ /* Error occurred */ create_message('Error: Unknown status.'); create_message($(button).text('Run')); bot_running = false; } } /* Creates a message */ function create_message(message){ console.log(message); $('#status_div').prepend(message + '<br />'); } /* Sets the max bet */ function set_max_bet(){ /* Retrieve max bet */ var txt_max_value = parseFloat($.trim($('#max_bet').val())); /* Check if new bet is not a number */ if(isNaN(txt_max_value) == false){ /* Set max bet and display to user */ $('#max_bet').data('max_bet', txt_max_value); create_message('<b>New Max Bet: ' + txt_max_value + "</b>"); } else{ create_message('<p>!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); create_message('Max bet is not a number, not updated.'); create_message('Current Max Bet: ' + max_bet); create_message('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!</p>'); } } /* Displays button to start bot etc */ function initialise_bookmarklet(){ /* Create vars */ var controls; var div_styles = "max-width:250px; width:250px;position: fixed; top: 10px; left: 10px; text-align: left; background-color: rgba(238, 238, 238, 0.84); padding: 10px; border: 1px solid rgba(116, 116, 116, 0.46); border-radius: 3px; box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.2); color: #333;"; var status_div = "<div id='status_div' style='font-size: 85%; max-width: 250px; position: fixed; bottom: 10px; left: 10px; text-align: left; background-color: rgb(15, 15, 15); padding: 10px; border: 1px solid rgba(31, 31, 31, 0.46); border-radius: 3px; box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.2); color: #1D9931; width: 250px; height: 200px; overflow: hidden;'></div>"; /* Set controls */ controls = "<div style='" + div_styles + "'>" + /* Wrapper start */ "Timeout: <br />" + "<input type='text' id='bot_timeout' value='500'/><button id='bookmarklet_controls' onClick='bot_status_change(this);'>Run</button><br />&nbsp;<br />" + /* Timeout button */ "Max Bet: <br />" + "<input type='text' id='max_bet' value='0.1' data-max_bet='0.1'><button id='btn_set_bet' onClick='set_max_bet();'>Set</button>" + /* Max Bet */ "&nbsp;<br /> <p style='margin-top:10px;'> Timeout: How many milliseconds the bot should wait between each bet. </p> <p style='margin-top:10px;'> Max Bet: The bot will revert to the reset amount if the bet exceeds this value (eg. 0.041) </p>" + "</div>"; /* Close wrapper */ /* Append status div */ controls += status_div; /* Add button to body */ $('body').append(controls); }

To add the bookmarklet, simply create a bookmark using the code above as the url. Go to CoinRoll, enter a bet and a starting value of 0.0001. Finally, click the bookmark icon, choose your max bet and hit start.

Martingale Bot for CoinRoll.it

Martingale Bot for CoinRoll.it

Note that this is just a quick script and has a lot of potential to be optimised. I should also mention that this is not an exploit, just a bot. The martingale system is still gambling and if you play long enough you WILL lose.

Installing SQL Developer on Ubuntu – make-sqldeveloper-package chmod: missing operand after `755′

Hey everyone,

I was following a guide while trying to install SQL Developer on Ubuntu, however I ran into the following error:

make-sqldeveloper-package chmod: missing operand after `755′

 

To fix it, simply change line number #381 in ‘/usr/bin /make-sqldeveloper-package’ as follows:

Original

${FIND} "${OPTDIR}" ! \( -type d -o -name "*.jar" \) |${XARGS} ${XARGS_OPTS} ${FILE} ${FILE_OPTS} |${GREP} ${GREP_OPTS} "shell script text executable" |${CUT} ${CUT_OPTS_FUNC_CLEAN} |${XARGS} ${XARGS_OPTS} ${CHMOD} ${CHMOD_OPTS}

Modified

${FIND} "${OPTDIR}" ! \( -type d -o -name "*.jar" \) |${XARGS} ${XARGS_OPTS} ${FILE} ${FILE_OPTS} |${GREP} ${GREP_OPTS} "shell script" | ${GREP} ${GREP_OPTS} "text executable" |${CUT} ${CUT_OPTS_FUNC_CLEAN} |${XARGS} ${XARGS_OPTS} ${CHMOD} ${CHMOD_OPTS}

Thanks to this blog post for the solution, just note that it is Polish.

Let me know if you have any issues!

Additional Logging – Heroku

Hey everyone,

I needed to do a fair bit of logging and came across a heroku guide that shows how to make things a little easier.

Change logging level to debug:
heroku config:add LOG_LEVEL=DEBUG

View a live(ish) feed of errors:
heroku logs –tail

If you’re aware of any other useful bits please let me know!