SlideShare a Scribd company logo
Mobile Hacking
                 through
     Linux Drivers


© 2012 Anil Kumar Pugalia <email@sarika-pugs.com>
               All Rights Reserved.
What to Expect?
Objective
  Usual Linux Kernel Hacking Techniques
  Tools to do Reverse-engineering
Assumptions
  Linux Kernel is already ported onto a Mobile
  Getting into the mobile has been figured out




         © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   2
                        All Rights Reserved.
The Hacking Architecture
                      User Space
             (provides interface for hacking)


                     Kernel Space
       (provides functionalities & facilities to hack)




                        Hardware
                  (is what needs Hacking)




                    System Call I/F
                      (the connector)



   © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>     3
                  All Rights Reserved.
Kernel Space Functionality
Process Management
Memory Management
Device Management
Storage Management
Network Management




       © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   4
                      All Rights Reserved.
Kernel Driver Ecosystem
bash           gvim        X Server          ssh           gcc          firefox

  Process         Memory           Device
                                                   File Systems     Networking
Management      Management         Control

Concurrency           Virtual      Ttys &          Files & Dirs:   Connectivity
MultiTasking          Memory    Device Access         The VFS
Architecture                     Character         Filesystem        Network
                  Memory
Dependent                         Drivers             Layer         Subsystem
                  Manager
   Code                              &             Block Layer       Interface
                                  Friends           & Drivers         Drivers
       Hardware Protocol Layers like PCI, USB, I2C, RS232, ...



                                 Consoles,          Disks &          Network
    CPU           Memory             `
                                    etc              CDs            Interfaces

               © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>                  5
                              All Rights Reserved.
Kernel Source Organization
/usr/src/linux/

             arch/<arch>
                    mm
                  drivers

                     fs          char     mtd/ide       net     pci       serial    usb   ...
                   block
                    net
                  include
                                 linux     asm-<arch>

                  init      kernel       ipc      lib           scripts          tools

                  crypto       firmware        security       sound        ...

                          © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>                     6
                                         All Rights Reserved.
Show me the Source Code




 © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   7
                All Rights Reserved.
Kernel Build System
Key components
  Makefile
  Kconfig
Configuring the Makefile
  Setting up the kernel version (specially for the
  Desktops)
  For Cross Compilation, need to setup
    ARCH
    CROSS_COMPILE
  Or, invoke make with these options
            © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   8
                           All Rights Reserved.
Kernel Configuration
make config
make menuconfig
make xconfig
Others
 make defconfig
 make oldconfig
 make <specific>config


         © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   9
                        All Rights Reserved.
Kernel Compilation
After configuring the kernel, we are all set to build it
Build Methods
  make vmlinux – To build everything configured for a kernel image
  make modules – To build only configured modules
  make – To build everything configured (kernel image & modules)
  make modules_prepare – To only prepare for building modules
Cleaning Methods
  make clean – Simple clean
  make mrproper – Complete sweep clean, incl. Configs




                © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>    10
                               All Rights Reserved.
Linux Kernel Images
Kernel Image should be understood by Stage 2 Bootloader
Default kernel compilation builds vmlinux
vmlinux is understood only by the desktop bootloaders
So, for embedded systems, we would typically have to do the
following
  Creating linux.bin using <cross>-objcopy
    Example: arm-linux-objcopy -O binary vmlinux linux.bin
  And then, convert it into the bootloader specific image using some
  bootloader utility. For u-boot, it is done using mkimage
    Example: mkimage -A arm -O linux -T kernel -C none -a 20008000 -e 20008000
    -n “Custom” -d linux.bin uImage.arm




                © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>                11
                               All Rights Reserved.
Powerful Kernel Arguments
console – Boot up & access interface
root – Base file system contents
mem – Limit the RAM usage
nfsroot – Base file system over nfs
ip – IP address on boot
...



        © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   12
                       All Rights Reserved.
Do we really need to build the kernel?

              Not really.
  Alternative: Use Modules instead.


       © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   13
                      All Rights Reserved.
W's of a Module?
Hot plug-n-play Driver
Dynamically Loadable & Unloadable
Linux – the first OS to have such a feature
Later many followed suit
Enables fast hacking cycle
File: <module>.ko (Kernel Object)
  <module>.o wrapped with kernel signature

        © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   14
                       All Rights Reserved.
Module Commands
lsmod – List modules
insmod <mod_file> – Load module
rmmod <module> – Unload module
modprobe <module> – Auto load module




        © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   15
                       All Rights Reserved.
The Module Constructor
static int __init mfd_init(void)
{


    ...


    return 0;
}
module_init(mfd_init);
                © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   16
                               All Rights Reserved.
The Module Destructor
static void __exit mfd_exit(void)
{


    ...


}
module_exit(mfd_exit);

            © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   17
                           All Rights Reserved.
Typical Makefile
ifeq (${KERNELRELEASE},)

       KERNEL_SOURCE := <kernel source directory path>

       PWD := $(shell pwd)

default:

       $(MAKE) -C ${KERNEL_SOURCE} SUBDIRS=$(PWD) modules

clean:

       $(MAKE) -C ${KERNEL_SOURCE} SUBDIRS=$(PWD) clean

else

       obj-m += <module>.o

endif




                       © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   18
                                      All Rights Reserved.
How to Hack?




© 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   19
               All Rights Reserved.
printk & syslogd
Header: <linux/kernel.h>
Arguments: Same as printf
Format Specifiers: All as in printf, except float & double related
Additionally, a initial 3 character sequence for Log Level
  KERN_EMERG       "<0>" /* system is unusable */
  KERN_ALERT      "<1>" /* action must be taken immediately */
  KERN_CRIT      "<2>" /* critical conditions */
  KERN_ERR       "<3>" /* error conditions */
  KERN_WARNING       "<4>" /* warning conditions */
  KERN_NOTICE      "<5>" /* normal but significant condition */
  KERN_INFO      "<6>" /* informational */
  KERN_DEBUG       "<7>" /* debug-level messages */


               © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>     20
                              All Rights Reserved.
Logs & Kernel Windows
Log View Commands
 dmesg | tail
 tail /var/log/messages
Kernel Windows
 /proc
 /sys
Peeping Commands
 cat <window_file>
 Utilities: sysfsutils, sysdiag
         © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   21
                        All Rights Reserved.
Cool Kernel Windows
Trivial ones
  /proc/cpuinfo
  /proc/meminfo
  /proc/devices
  /proc/filesystems
  /proc/partitions
  /proc/interrupts
  /proc/softirqs
Hacking Experts
  /proc/kallsyms
  /proc/kcore
  /proc/iomem
  /proc/ioports
  /proc/bus/*/devices
  /sys/class
                     © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   22
                                    All Rights Reserved.
Kernel Probes
kprobes → CONFIG_KPROBES
jprobes → Specialized Kprobes
  For probing function entry points
kretprobes → Return Kprobes
  For probing function exit points




         © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   23
                        All Rights Reserved.
Kernel Hacking Related Options
CONFIG_PRINTK_TIME
CONFIG_DEBUG_SLAB
 CONFIG_DEBUG_HIMEM, CONFIG_DEBUG_PAGE_ALLOC
CONFIG_DEBUG_SPINLOCK
CONFIG_MAGIC_SYSRQ (kdump related)
CONFIG_DETECT_SOFTLOCKUP
CONFIG_DEBUG_STACKOVERFLOW
CONFIG_DEBUG_STACK_USAGE
CONFIG_BUG
 CONFIG_DEBUG_BUGVERBOSE
CONFIG_KALLSYMS (for debugging oops using gdb)
 Under “General setup” → “Configure Std Kernel ... (for small systems)”
              © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>           24
                             All Rights Reserved.
Memory & Device Access

                                                               RAM
                                           Memory
                                           Controller
   32
                                      32

Data Bus          CPU               Address Bus
                                      32


                                             Bus
                                           Controller
                                                                  Device
               uController                                     Address Space
    32

           © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>                   25
                          All Rights Reserved.
Kernel Space Memory Access
Virtual Address on Physical Address
  Header: <linux/gfp.h>
    unsigned long __get_free_pages(flags, order); etc
    void free_pages(addr, order); etc
  Header: <linux/slab.h>
    void *kmalloc(size_t size, gfp_t flags);
       GFP_USER, GFP_KERNEL, GFP_DMA
    void kfree(void *obj);
  Header: <linux/vmalloc.h>
    void *vmalloc(unsigned long size);
    void vfree(void *addr);
           © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   26
                          All Rights Reserved.
Kernel Space Device Access
Virtual Address for Bus/IO Address
  Header: <asm/io.h>
    void *ioremap(phys_addr_t bus_addr, unsigned long size);
    void iounmap(void *addr);
I/O Memory Access
  Header: <asm/io.h>
    u[8|16|32] ioread[8|16|32](void *addr);
    void iowrite[8|16|32](u[8|16|32] value, void *addr);

Kernel Window: /proc/iomem

          © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>    27
                         All Rights Reserved.
x86 Hardware Architecture

                                                                        RAM
                                                    North
                          32                        Bridge

                                               32
              32
                               x86           Address Bus
               Data Bus
                               CPU
                                               32

I/O Ports /                      I/O Line

 Address                                            South
  Space                              16             Bridge               (PCI) Device
                          32                                            Address Space



                    © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>                   28
                                   All Rights Reserved.
I/O Access (x86* specific)
I/O Port Access
  u8 inb(unsigned long port);
  u16 inw(unsigned long port);
  u32 inl(unsigned long port);
  void outb(u8 value, unsigned long port);
  void outw(u16 value, unsigned long port);
  void outl(u32 value, unsigned long port);

Header: <asm/io.h>
Kernel Window: /proc/ioports

            © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   29
                           All Rights Reserved.
Hacking from User Space
Decoding Code
 objdump -d <object_file> – Disassemble
 nm <object_file> – List symbols
Tracing: strace [options] <command>
Decoding Bus Devices
 PCI – lspci [-v[v]]
 USB – lsusb [-v]


         © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   30
                        All Rights Reserved.
What all have we learnt talked?
 Linux' Hacking Architecture
 Configuring & Compiling the Linux Kernel
 Boot Control using Kernel Boot Args
 Hacking Flexibility w/ Linux Modules
 Ready-made Hacking Tools & Techniques




         © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   31
                        All Rights Reserved.
Any Queries?




© 2012 Anil Kumar Pugalia <email@sarika-pugs.com>   32
               All Rights Reserved.
Contact Me
Mailing List
  computerclubin@googlegroups.com
Website
  http://www.sysplay.in
Email
  email@sarika-pugs.com
Twitter
  anil_pugalia
          © 2012 Anil Kumar Pugalia <email@sarika-pugs.com>
                         All Rights Reserved.

More Related Content

What's hot

Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingAnil Kumar Pugalia
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
SysPlay eLearning Academy for You
 
Linux Internals Part - 3
Linux Internals Part - 3Linux Internals Part - 3
Linux Internals Part - 3
SysPlay eLearning Academy for You
 
POSIX Threads
POSIX ThreadsPOSIX Threads
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
Anil Kumar Pugalia
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded SystemsAnil Kumar Pugalia
 
Kernel Programming
Kernel ProgrammingKernel Programming
Kernel Programming
Anil Kumar Pugalia
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
Anil Kumar Pugalia
 
SPI Drivers
SPI DriversSPI Drivers
BeagleBoard-xM Booting Process
BeagleBoard-xM Booting ProcessBeagleBoard-xM Booting Process
BeagleBoard-xM Booting Process
SysPlay eLearning Academy for You
 

What's hot (20)

Linux Porting
Linux PortingLinux Porting
Linux Porting
 
Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & Profiling
 
Signals
SignalsSignals
Signals
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Embedded Storage Management
Embedded Storage ManagementEmbedded Storage Management
Embedded Storage Management
 
Toolchain
ToolchainToolchain
Toolchain
 
Linux Internals Part - 3
Linux Internals Part - 3Linux Internals Part - 3
Linux Internals Part - 3
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Linux Network Management
Linux Network ManagementLinux Network Management
Linux Network Management
 
POSIX Threads
POSIX ThreadsPOSIX Threads
POSIX Threads
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded Systems
 
Processes
ProcessesProcesses
Processes
 
Kernel Programming
Kernel ProgrammingKernel Programming
Kernel Programming
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
Block Drivers
Block DriversBlock Drivers
Block Drivers
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
BeagleBoard-xM Booting Process
BeagleBoard-xM Booting ProcessBeagleBoard-xM Booting Process
BeagleBoard-xM Booting Process
 

Viewers also liked

Bootloaders
BootloadersBootloaders
Bootloaders
Anil Kumar Pugalia
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISPAnil Kumar Pugalia
 
Embedded C
Embedded CEmbedded C
Embedded C
Anil Kumar Pugalia
 
Threads
ThreadsThreads
References
ReferencesReferences
References
Anil Kumar Pugalia
 
Interrupts
InterruptsInterrupts
Interrupts
Anil Kumar Pugalia
 

Viewers also liked (13)

Bootloaders
BootloadersBootloaders
Bootloaders
 
Board Bringup
Board BringupBoard Bringup
Board Bringup
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISP
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Timers
TimersTimers
Timers
 
System Calls
System CallsSystem Calls
System Calls
 
Embedded C
Embedded CEmbedded C
Embedded C
 
Threads
ThreadsThreads
Threads
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
References
ReferencesReferences
References
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 
Interrupts
InterruptsInterrupts
Interrupts
 

Similar to Mobile Hacking using Linux Drivers

Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
dibyajyotig
 
Building
BuildingBuilding
Building
Satpal Parmar
 
Introduction to Linux Kernel Development
Introduction to Linux Kernel DevelopmentIntroduction to Linux Kernel Development
Introduction to Linux Kernel Development
Levente Kurusa
 
Introduction to lkm
Introduction to lkmIntroduction to lkm
Introduction to lkm
pradeep_tewani
 
Reliability, Availability and Serviceability on Linux
Reliability, Availability and Serviceability on LinuxReliability, Availability and Serviceability on Linux
Reliability, Availability and Serviceability on Linux
Samsung Open Source Group
 
Android memory analysis Debug slides.pdf
Android memory analysis Debug slides.pdfAndroid memory analysis Debug slides.pdf
Android memory analysis Debug slides.pdf
VishalKumarJha10
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
Priyank Kapadia
 
Linux scheduler
Linux schedulerLinux scheduler
Linux scheduler
Liran Ben Haim
 
Genode Compositions
Genode CompositionsGenode Compositions
Genode Compositions
Vasily Sartakov
 
Visão geral do hardware do servidor System z e Linux on z - Concurso Mainframe
Visão geral do hardware do servidor System z e Linux on z - Concurso MainframeVisão geral do hardware do servidor System z e Linux on z - Concurso Mainframe
Visão geral do hardware do servidor System z e Linux on z - Concurso Mainframe
Anderson Bassani
 
Oracle Solaris 11.1 New Features
Oracle Solaris 11.1 New FeaturesOracle Solaris 11.1 New Features
Oracle Solaris 11.1 New FeaturesOrgad Kimchi
 
ABS 2012 - Android Device Porting Walkthrough
ABS 2012 - Android Device Porting WalkthroughABS 2012 - Android Device Porting Walkthrough
ABS 2012 - Android Device Porting Walkthrough
Benjamin Zores
 
the NML project
the NML projectthe NML project
the NML projectLei Yang
 
Systemd for developers
Systemd for developersSystemd for developers
Systemd for developers
Alison Chaiken
 
Tuning systemd for embedded
Tuning systemd for embeddedTuning systemd for embedded
Tuning systemd for embedded
Alison Chaiken
 
CloudNativeTurkey - Lines of Defence.pdf
CloudNativeTurkey - Lines of Defence.pdfCloudNativeTurkey - Lines of Defence.pdf
CloudNativeTurkey - Lines of Defence.pdf
Koray Oksay
 

Similar to Mobile Hacking using Linux Drivers (20)

Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
 
Building
BuildingBuilding
Building
 
Introduction to Linux Kernel Development
Introduction to Linux Kernel DevelopmentIntroduction to Linux Kernel Development
Introduction to Linux Kernel Development
 
Introduction to lkm
Introduction to lkmIntroduction to lkm
Introduction to lkm
 
Studienarb linux kernel-dev
Studienarb linux kernel-devStudienarb linux kernel-dev
Studienarb linux kernel-dev
 
Embedded I/O Management
Embedded I/O ManagementEmbedded I/O Management
Embedded I/O Management
 
Reliability, Availability and Serviceability on Linux
Reliability, Availability and Serviceability on LinuxReliability, Availability and Serviceability on Linux
Reliability, Availability and Serviceability on Linux
 
Android memory analysis Debug slides.pdf
Android memory analysis Debug slides.pdfAndroid memory analysis Debug slides.pdf
Android memory analysis Debug slides.pdf
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
 
TSRT Crashes
TSRT CrashesTSRT Crashes
TSRT Crashes
 
Linux scheduler
Linux schedulerLinux scheduler
Linux scheduler
 
Genode Compositions
Genode CompositionsGenode Compositions
Genode Compositions
 
Visão geral do hardware do servidor System z e Linux on z - Concurso Mainframe
Visão geral do hardware do servidor System z e Linux on z - Concurso MainframeVisão geral do hardware do servidor System z e Linux on z - Concurso Mainframe
Visão geral do hardware do servidor System z e Linux on z - Concurso Mainframe
 
Oracle Solaris 11.1 New Features
Oracle Solaris 11.1 New FeaturesOracle Solaris 11.1 New Features
Oracle Solaris 11.1 New Features
 
ABS 2012 - Android Device Porting Walkthrough
ABS 2012 - Android Device Porting WalkthroughABS 2012 - Android Device Porting Walkthrough
ABS 2012 - Android Device Porting Walkthrough
 
the NML project
the NML projectthe NML project
the NML project
 
Systemd for developers
Systemd for developersSystemd for developers
Systemd for developers
 
Tuning systemd for embedded
Tuning systemd for embeddedTuning systemd for embedded
Tuning systemd for embedded
 
CloudNativeTurkey - Lines of Defence.pdf
CloudNativeTurkey - Lines of Defence.pdfCloudNativeTurkey - Lines of Defence.pdf
CloudNativeTurkey - Lines of Defence.pdf
 

More from Anil Kumar Pugalia

File System Modules
File System ModulesFile System Modules
File System Modules
Anil Kumar Pugalia
 
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
Anil Kumar Pugalia
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
Anil Kumar Pugalia
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
Anil Kumar Pugalia
 

More from Anil Kumar Pugalia (11)

File System Modules
File System ModulesFile System Modules
File System Modules
 
System Calls
System CallsSystem Calls
System Calls
 
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
 
Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
Power of vi
Power of viPower of vi
Power of vi
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
 
"make" system
"make" system"make" system
"make" system
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
 
RPM Building
RPM BuildingRPM Building
RPM Building
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Linux File System
Linux File SystemLinux File System
Linux File System
 

Recently uploaded

Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 

Recently uploaded (20)

Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

Mobile Hacking using Linux Drivers

  • 1. Mobile Hacking through Linux Drivers © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved.
  • 2. What to Expect? Objective Usual Linux Kernel Hacking Techniques Tools to do Reverse-engineering Assumptions Linux Kernel is already ported onto a Mobile Getting into the mobile has been figured out © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 2 All Rights Reserved.
  • 3. The Hacking Architecture User Space (provides interface for hacking) Kernel Space (provides functionalities & facilities to hack) Hardware (is what needs Hacking) System Call I/F (the connector) © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 3 All Rights Reserved.
  • 4. Kernel Space Functionality Process Management Memory Management Device Management Storage Management Network Management © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 4 All Rights Reserved.
  • 5. Kernel Driver Ecosystem bash gvim X Server ssh gcc firefox Process Memory Device File Systems Networking Management Management Control Concurrency Virtual Ttys & Files & Dirs: Connectivity MultiTasking Memory Device Access The VFS Architecture Character Filesystem Network Memory Dependent Drivers Layer Subsystem Manager Code & Block Layer Interface Friends & Drivers Drivers Hardware Protocol Layers like PCI, USB, I2C, RS232, ... Consoles, Disks & Network CPU Memory ` etc CDs Interfaces © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 5 All Rights Reserved.
  • 6. Kernel Source Organization /usr/src/linux/ arch/<arch> mm drivers fs char mtd/ide net pci serial usb ... block net include linux asm-<arch> init kernel ipc lib scripts tools crypto firmware security sound ... © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 6 All Rights Reserved.
  • 7. Show me the Source Code © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 7 All Rights Reserved.
  • 8. Kernel Build System Key components Makefile Kconfig Configuring the Makefile Setting up the kernel version (specially for the Desktops) For Cross Compilation, need to setup ARCH CROSS_COMPILE Or, invoke make with these options © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 8 All Rights Reserved.
  • 9. Kernel Configuration make config make menuconfig make xconfig Others make defconfig make oldconfig make <specific>config © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 9 All Rights Reserved.
  • 10. Kernel Compilation After configuring the kernel, we are all set to build it Build Methods make vmlinux – To build everything configured for a kernel image make modules – To build only configured modules make – To build everything configured (kernel image & modules) make modules_prepare – To only prepare for building modules Cleaning Methods make clean – Simple clean make mrproper – Complete sweep clean, incl. Configs © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 10 All Rights Reserved.
  • 11. Linux Kernel Images Kernel Image should be understood by Stage 2 Bootloader Default kernel compilation builds vmlinux vmlinux is understood only by the desktop bootloaders So, for embedded systems, we would typically have to do the following Creating linux.bin using <cross>-objcopy Example: arm-linux-objcopy -O binary vmlinux linux.bin And then, convert it into the bootloader specific image using some bootloader utility. For u-boot, it is done using mkimage Example: mkimage -A arm -O linux -T kernel -C none -a 20008000 -e 20008000 -n “Custom” -d linux.bin uImage.arm © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 11 All Rights Reserved.
  • 12. Powerful Kernel Arguments console – Boot up & access interface root – Base file system contents mem – Limit the RAM usage nfsroot – Base file system over nfs ip – IP address on boot ... © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 12 All Rights Reserved.
  • 13. Do we really need to build the kernel? Not really. Alternative: Use Modules instead. © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 13 All Rights Reserved.
  • 14. W's of a Module? Hot plug-n-play Driver Dynamically Loadable & Unloadable Linux – the first OS to have such a feature Later many followed suit Enables fast hacking cycle File: <module>.ko (Kernel Object) <module>.o wrapped with kernel signature © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 14 All Rights Reserved.
  • 15. Module Commands lsmod – List modules insmod <mod_file> – Load module rmmod <module> – Unload module modprobe <module> – Auto load module © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 15 All Rights Reserved.
  • 16. The Module Constructor static int __init mfd_init(void) { ... return 0; } module_init(mfd_init); © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 16 All Rights Reserved.
  • 17. The Module Destructor static void __exit mfd_exit(void) { ... } module_exit(mfd_exit); © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 17 All Rights Reserved.
  • 18. Typical Makefile ifeq (${KERNELRELEASE},) KERNEL_SOURCE := <kernel source directory path> PWD := $(shell pwd) default: $(MAKE) -C ${KERNEL_SOURCE} SUBDIRS=$(PWD) modules clean: $(MAKE) -C ${KERNEL_SOURCE} SUBDIRS=$(PWD) clean else obj-m += <module>.o endif © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 18 All Rights Reserved.
  • 19. How to Hack? © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 19 All Rights Reserved.
  • 20. printk & syslogd Header: <linux/kernel.h> Arguments: Same as printf Format Specifiers: All as in printf, except float & double related Additionally, a initial 3 character sequence for Log Level KERN_EMERG "<0>" /* system is unusable */ KERN_ALERT "<1>" /* action must be taken immediately */ KERN_CRIT "<2>" /* critical conditions */ KERN_ERR "<3>" /* error conditions */ KERN_WARNING "<4>" /* warning conditions */ KERN_NOTICE "<5>" /* normal but significant condition */ KERN_INFO "<6>" /* informational */ KERN_DEBUG "<7>" /* debug-level messages */ © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 20 All Rights Reserved.
  • 21. Logs & Kernel Windows Log View Commands dmesg | tail tail /var/log/messages Kernel Windows /proc /sys Peeping Commands cat <window_file> Utilities: sysfsutils, sysdiag © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 21 All Rights Reserved.
  • 22. Cool Kernel Windows Trivial ones /proc/cpuinfo /proc/meminfo /proc/devices /proc/filesystems /proc/partitions /proc/interrupts /proc/softirqs Hacking Experts /proc/kallsyms /proc/kcore /proc/iomem /proc/ioports /proc/bus/*/devices /sys/class © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 22 All Rights Reserved.
  • 23. Kernel Probes kprobes → CONFIG_KPROBES jprobes → Specialized Kprobes For probing function entry points kretprobes → Return Kprobes For probing function exit points © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 23 All Rights Reserved.
  • 24. Kernel Hacking Related Options CONFIG_PRINTK_TIME CONFIG_DEBUG_SLAB CONFIG_DEBUG_HIMEM, CONFIG_DEBUG_PAGE_ALLOC CONFIG_DEBUG_SPINLOCK CONFIG_MAGIC_SYSRQ (kdump related) CONFIG_DETECT_SOFTLOCKUP CONFIG_DEBUG_STACKOVERFLOW CONFIG_DEBUG_STACK_USAGE CONFIG_BUG CONFIG_DEBUG_BUGVERBOSE CONFIG_KALLSYMS (for debugging oops using gdb) Under “General setup” → “Configure Std Kernel ... (for small systems)” © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 24 All Rights Reserved.
  • 25. Memory & Device Access RAM Memory Controller 32 32 Data Bus CPU Address Bus 32 Bus Controller Device uController Address Space 32 © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 25 All Rights Reserved.
  • 26. Kernel Space Memory Access Virtual Address on Physical Address Header: <linux/gfp.h> unsigned long __get_free_pages(flags, order); etc void free_pages(addr, order); etc Header: <linux/slab.h> void *kmalloc(size_t size, gfp_t flags); GFP_USER, GFP_KERNEL, GFP_DMA void kfree(void *obj); Header: <linux/vmalloc.h> void *vmalloc(unsigned long size); void vfree(void *addr); © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 26 All Rights Reserved.
  • 27. Kernel Space Device Access Virtual Address for Bus/IO Address Header: <asm/io.h> void *ioremap(phys_addr_t bus_addr, unsigned long size); void iounmap(void *addr); I/O Memory Access Header: <asm/io.h> u[8|16|32] ioread[8|16|32](void *addr); void iowrite[8|16|32](u[8|16|32] value, void *addr); Kernel Window: /proc/iomem © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 27 All Rights Reserved.
  • 28. x86 Hardware Architecture RAM North 32 Bridge 32 32 x86 Address Bus Data Bus CPU 32 I/O Ports / I/O Line Address South Space 16 Bridge (PCI) Device 32 Address Space © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 28 All Rights Reserved.
  • 29. I/O Access (x86* specific) I/O Port Access u8 inb(unsigned long port); u16 inw(unsigned long port); u32 inl(unsigned long port); void outb(u8 value, unsigned long port); void outw(u16 value, unsigned long port); void outl(u32 value, unsigned long port); Header: <asm/io.h> Kernel Window: /proc/ioports © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 29 All Rights Reserved.
  • 30. Hacking from User Space Decoding Code objdump -d <object_file> – Disassemble nm <object_file> – List symbols Tracing: strace [options] <command> Decoding Bus Devices PCI – lspci [-v[v]] USB – lsusb [-v] © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 30 All Rights Reserved.
  • 31. What all have we learnt talked? Linux' Hacking Architecture Configuring & Compiling the Linux Kernel Boot Control using Kernel Boot Args Hacking Flexibility w/ Linux Modules Ready-made Hacking Tools & Techniques © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 31 All Rights Reserved.
  • 32. Any Queries? © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> 32 All Rights Reserved.
  • 33. Contact Me Mailing List computerclubin@googlegroups.com Website http://www.sysplay.in Email email@sarika-pugs.com Twitter anil_pugalia © 2012 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved.