Skip to content

Instantly share code, notes, and snippets.

import Cocoa
let workspace = NSWorkspace.sharedWorkspace()
let activeApps = workspace.runningApplications
for app in activeApps {
if app.active {
let listOptions = CGWindowListOption(arrayLiteral: CGWindowListOption.OptionOnScreenOnly)
let windowList : NSArray = CGWindowListCopyWindowInfo(listOptions, 0)!
for window in windowList {
if (window["kCGWindowOwnerName"] as! String) == app.localizedName {
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.xml with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost:443
from http.server import HTTPServer, BaseHTTPRequestHandler
import ssl
@stefanocoding
stefanocoding / draw_curve.py
Created October 5, 2017 12:50
Plot curve using OpenCV instead of Matplotlib's plot().
# If you have something like this
matplotlib.pyplot.plot(x_values, y_values, color='yellow')
# You can do the same on OpenCV like this
curve = numpy.column_stack((x_values.astype(numpy.int32), y_values.astype(numpy.int32)))
cv2.polylines(image, [curve], False, (0,255,255))
# And if you need to plot more curves just add them as an element to the array of polygonal curves
curve1 = numpy.column_stack((x1.astype(numpy.int32), y1.astype(numpy.int32)))
curve2 = numpy.column_stack((x2.astype(numpy.int32), y2.astype(numpy.int32)))
@stefanocoding
stefanocoding / huawei_e397b.md
Created February 24, 2018 03:43
Make modem Huawei E397B work on Mac OS X
  1. Install the Connection Manager that is launched when you connect the modem to the Mac
  2. Download the source of usb_modeswitch from here http://www.draisberghof.de/usb_modeswitch/ (at the moment of writing this the file appears with the name usb-modeswitch-2.5.2.tar.bz2)
  3. Run make in the directory of the source you downloaded
  4. Run sudo ./usb_modeswitch -v12d1 -p1505 -X in the same directory

If the last step returns an error (I don't remember the error now, but I was getting an error related to usb_modeswitch not being able to take control of the modem to perfom changes):

  1. Unplug the modem and plug it again
  2. As soon as you plug the modem again, run sudo ./usb_modeswitch -v12d1 -p1505 -X repatedly until you get a successful result
  3. Open Connection Manager and your modem is going to be detected
@stefanocoding
stefanocoding / highlight_in_scope.py
Created April 9, 2018 15:01
Burp Extension to highlight in the Proxy requests that are in scope
from burp import IBurpExtender
from burp import IProxyListener
class BurpExtender(IBurpExtender, IProxyListener):
def registerExtenderCallbacks(self, callbacks):
self.helpers = callbacks.getHelpers()
self.callbacks = callbacks
callbacks.setExtensionName('Highlight in scope')
callbacks.registerProxyListener(self)
@stefanocoding
stefanocoding / copy_cookie_header.py
Last active October 18, 2019 16:25
This Burp extension adds an item to the context menu - when right-clicking in the request in Proxy or Repeater - to copy the entire "Cookie" header without having to manually select it and press Ctrl+C. It's useful for me when updating session information of tabs in the Repeater for saved projects.
@stefanocoding
stefanocoding / window.name.md
Created October 5, 2018 17:19
When `window.name` is evaluated #xss

The following is not a bug in the web browsers - it's supposed to work this way - but is useful in some cases like the one described.

In one of the Javascript files loaded by an endpoint of a private program, they were taking the value of window.name and passing it to something like eval([here]) or setTimeout([here], [some_milliseconds]), I don't remember correctly... The thing is that the value of window.name was being evaluated as Javascript code, so window.name = 'alert()' showed an alert(). To use this behavior for an attack, you have two options:

  1. if the endpoint is frameable from any domain, you can create an <iframe name='[javascript_code_here]' src='[vulnerable_endpoint]'></iframe>
  2. if it's not frameable, you can set window.name = '[javascript_code_here]' in your own domain and then redirect to the vulnerable endpoint

The one I used was the second option. 💰

@stefanocoding
stefanocoding / macos_on_ubuntu.md
Last active May 18, 2023 12:17
Install macOS in a VirtualBox machine on Ubuntu

Important: I'm writing this when the last version of macOS (and the one I have installed) is Mojave. There is already a script which installs Mojave in a virtual machine here https://github.com/img2tab/okiomov. But if you are curios how to do everything manually to install High Sierra, then this guide may be useful.

After reading a few articles I ended up with these steps:

  1. On macOS, download the High Sierra installer (even if you have Mojave installed): https://itunes.apple.com/us/app/macos-high-sierra/id1246284741?ls=1&mt=12
  2. If the High Sierra Installer starts, quit it.
  3. Open "Disk Utility".
  4. Click on "File" > "New Image" > "Blank image...". Or just press cmd+N.
@stefanocoding
stefanocoding / ubuntu_nvidia_macbook_backlight.md
Created December 18, 2018 23:55
Fix not working backlight when using NVidia propietary driver on Ubuntu 18.04 installed in a Macbook Pro Mid 2014.

After installing the latest NVidia proprietary driver (version 390) using Software & Updates > Additional Drivers, it wasn't possible to change the backlight intensity/brightness of the screen.

The solution that worked for me was to run: sudo setpci -H1 -s 00:01.00 BRIDGE_CONTROL=0. If that solution works for you too, then you may want to make the change permanent. Otherwise, you will have to run the same command each time you power on your Macbook.

Steps to make the change permanent:

  1. Open "Terminal"
  2. Run sudo gedit /etc/rc.local
  3. Enter:
@stefanocoding
stefanocoding / activate_intel_gpu_on_macbookpro.md
Last active May 27, 2024 21:27
Activate integrated Intel GPU of a MacBook Pro Mid 2014 (MacBookPro11,3) on Ubuntu 18.04

This may work with other Macbook Pro models that have an Intel GPU and a NVidia one, but I only have proof that this works on a MacBook Pro Mid 2014 (MacBookPro11,3) with Ubuntu 18.04. If you want to be sure about which model you have, run sudo dmidecode -t system in the Terminal and you will see the information about the system including the serial number and product name (MacBookPro11,3 in my case). I'm assuming you have installed the NVidia propietary drivers, which can be installed from the application "Software & Updates" in the tab "Additional Drivers".

Steps to use the Intel GPU:

  1. Run lspci |grep VGA and check that only one line mentioning "NVIDIA" is printed. This is to be sure that you are required to do the following steps. If two lines appear, and one of those mentions "Intel", then you probably do not need to activate the GPU but only select it as the main GPU (jump to the step where you have to "Open nvidia-settings").
  2. Download apple_set_os.efi from https://github.com/0xbb/apple_se