# Kali NetHunter init

on init
    export TERMINFO /system/etc/terminfo
    export TERM linux

on boot
    # Execute files in /system/etc/init.d near the end of the boot sequence
    start run-parts
    # Save boot USB configuration for restoring after HID attacks
    start save-usb-config

service run-parts /system/xbin/busybox_nh run-parts /system/etc/init.d
    class late_start
    seclabel u:r:init:s0
    user root
    group root
    disabled
    oneshot

service save-usb-config /system/bin/sh /sbin/usb_config.sh save
    class late_start
    seclabel u:r:init:s0
    user root
    group root
    disabled
    oneshot

service reset-usb-config /system/bin/sh /sbin/usb_config.sh reset
    class late_start
    seclabel u:r:init:s0
    user root
    group root
    disabled
    oneshot

# After using HID attacks we should reset to OEM configuration
on property:sys.usb.config=reset
    start reset-usb-config

# HID attack support (emulated Microsoft Comfort Curve Keyboard 2000)
on property:sys.usb.config=hid
    stop adbd
    write /sys/class/android_usb/android0/enable 0
    write /sys/class/android_usb/android0/idVendor 045E
    write /sys/class/android_usb/android0/idProduct 00DD
    write /sys/class/android_usb/android0/bDeviceClass 0
    write /sys/class/android_usb/android0/bDeviceSubClass 0
    write /sys/class/android_usb/android0/bDeviceProtocol 0
    write /sys/class/android_usb/android0/iManufacturer "Microsoft"
    write /sys/class/android_usb/android0/iProduct "Microsoft USB Comfort Curve Keyboard 2000 (IntelliType Pro)"
    write /sys/class/android_usb/android0/functions hid
    write /sys/class/android_usb/android0/enable 1
    setprop sys.usb.state hid

# HID + Flash Drive attack support (emulated Kingston DataTraveler 2.0)
on property:sys.usb.config=hid,mass_storage
    stop adbd
    write /sys/class/android_usb/android0/enable 0
    write /sys/class/android_usb/f_mass_storage/lun/cdrom 0
    write /sys/class/android_usb/f_mass_storage/lun/ro 0
    write /sys/class/android_usb/f_mass_storage/lun/nofua 0
    write /sys/class/android_usb/android0/idVendor 0930
    write /sys/class/android_usb/android0/idProduct 6545
    write /sys/class/android_usb/android0/bDeviceClass 0
    write /sys/class/android_usb/android0/bDeviceSubClass 0
    write /sys/class/android_usb/android0/bDeviceProtocol 0
    write /sys/class/android_usb/android0/iManufacturer "Kingston"
    write /sys/class/android_usb/android0/iProduct "DataTraveler 2.0"
    write /sys/class/android_usb/android0/functions hid,mass_storage
    write /sys/class/android_usb/android0/enable 1
    setprop sys.usb.state hid,mass_storage
