Skip to content

Commit 5887ddc

Browse files
committed
Merge branch 'master' of github.com:HackTricks-wiki/hacktricks
2 parents 7b0e4ae + df17dc7 commit 5887ddc

10 files changed

Lines changed: 622 additions & 147 deletions

File tree

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@
423423
- [Joomla](network-services-pentesting/pentesting-web/joomla.md)
424424
- [JSP](network-services-pentesting/pentesting-web/jsp.md)
425425
- [Laravel](network-services-pentesting/pentesting-web/laravel.md)
426+
- [Microsoft Sharepoint](network-services-pentesting/pentesting-web/microsoft-sharepoint.md)
426427
- [Moodle](network-services-pentesting/pentesting-web/moodle.md)
427428
- [NextJS](network-services-pentesting/pentesting-web/nextjs.md)
428429
- [Nginx](network-services-pentesting/pentesting-web/nginx.md)

src/generic-methodologies-and-resources/basic-forensic-methodology/image-acquisition-and-mount.md

Lines changed: 123 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,114 +5,173 @@
55

66
## Acquisition
77

8+
> Always acquire **read-only** and **hash while you copy**. Keep the original device **write-blocked** and work only on verified copies.
9+
810
### DD
911

1012
```bash
11-
#This will generate a raw copy of the disk
12-
dd if=/dev/sdb of=disk.img
13+
# Generate a raw, bit-by-bit image (no on-the-fly hashing)
14+
dd if=/dev/sdb of=disk.img bs=4M status=progress conv=noerror,sync
15+
# Verify integrity afterwards
16+
sha256sum disk.img > disk.img.sha256
17+
```
18+
19+
### dc3dd / dcfldd
20+
21+
`dc3dd` is the actively maintained fork of dcfldd (DoD Computer Forensics Lab dd).
22+
23+
```bash
24+
# Create an image and calculate multiple hashes at acquisition time
25+
sudo dc3dd if=/dev/sdc of=/forensics/pc.img hash=sha256,sha1 hashlog=/forensics/pc.hashes log=/forensics/pc.log bs=1M
26+
```
27+
28+
### Guymager
29+
Graphical, multithreaded imager that supports **raw (dd)**, **EWF (E01/EWFX)** and **AFF4** output with parallel verification. Available in most Linux repos (`apt install guymager`).
30+
31+
```bash
32+
# Start in GUI mode
33+
sudo guymager
34+
# Or acquire from CLI (since v0.9.5)
35+
sudo guymager --simulate --input /dev/sdb --format EWF --hash sha256 --output /evidence/drive.e01
1336
```
1437

15-
### dcfldd
38+
### AFF4 (Advanced Forensics Format 4)
39+
40+
AFF4 is Google’s modern imaging format designed for *very* large evidence (sparse, resumable, cloud-native).
1641

1742
```bash
18-
#Raw copy with hashes along the way (more secur as it checks hashes while it's copying the data)
19-
dcfldd if=<subject device> of=<image file> bs=512 hash=<algorithm> hashwindow=<chunk size> hashlog=<hash file>
20-
dcfldd if=/dev/sdc of=/media/usb/pc.image hash=sha256 hashwindow=1M hashlog=/media/usb/pc.hashes
43+
# Acquire to AFF4 using the reference tool
44+
pipx install aff4imager
45+
sudo aff4imager acquire /dev/nvme0n1 /evidence/nvme.aff4 --hash sha256
46+
47+
# Velociraptor can also acquire AFF4 images remotely
48+
velociraptor --config server.yaml frontend collect --artifact Windows.Disk.Acquire --args device="\\.\\PhysicalDrive0" format=AFF4
2149
```
2250

23-
### FTK Imager
51+
### FTK Imager (Windows & Linux)
52+
53+
You can [download FTK Imager](https://accessdata.com/product-download) and create **raw, E01 or AFF4** images:
54+
55+
```bash
56+
ftkimager /dev/sdb evidence --e01 --case-number 1 --evidence-number 1 \
57+
--description 'Laptop seizure 2025-07-22' --examiner 'AnalystName' --compress 6
58+
```
2459

25-
You can [**download the FTK imager from here**](https://accessdata.com/product-download/debian-and-ubuntu-x64-3-1-1).
60+
### EWF tools (libewf)
2661

2762
```bash
28-
ftkimager /dev/sdb evidence --e01 --case-number 1 --evidence-number 1 --description 'A description' --examiner 'Your name'
63+
sudo ewfacquire /dev/sdb -u evidence -c 1 -d "Seizure 2025-07-22" -e 1 -X examiner --format encase6 --compression best
2964
```
3065

31-
### EWF
66+
### Imaging Cloud Disks
3267

33-
You can generate a disk image using the[ **ewf tools**](https://github.com/libyal/libewf).
68+
*AWS* – create a **forensic snapshot** without shutting down the instance:
3469

3570
```bash
36-
ewfacquire /dev/sdb
37-
#Name: evidence
38-
#Case number: 1
39-
#Description: A description for the case
40-
#Evidence number: 1
41-
#Examiner Name: Your name
42-
#Media type: fixed
43-
#Media characteristics: physical
44-
#File format: encase6
45-
#Compression method: deflate
46-
#Compression level: fast
47-
48-
#Then use default values
49-
#It will generate the disk image in the current directory
71+
aws ec2 create-snapshot --volume-id vol-01234567 --description "IR-case-1234 web-server 2025-07-22"
72+
# Copy the snapshot to S3 and download with aws cli / aws snowball
5073
```
5174

75+
*Azure* – use `az snapshot create` and export to a SAS URL. See the HackTricks page {{#ref}}
76+
../../cloud/azure/azure-forensics.md
77+
{{#endref}}
78+
79+
5280
## Mount
5381

54-
### Several types
82+
### Choosing the right approach
5583

56-
In **Windows** you can try to use the free version of Arsenal Image Mounter ([https://arsenalrecon.com/downloads/](https://arsenalrecon.com/downloads/)) to **mount the forensics image**.
84+
1. Mount the **whole disk** when you want the original partition table (MBR/GPT).
85+
2. Mount a **single partition file** when you only need one volume.
86+
3. Always mount **read-only** (`-o ro,norecovery`) and work on **copies**.
5787

58-
### Raw
88+
### Raw images (dd, AFF4-extracted)
5989

6090
```bash
61-
#Get file type
62-
file evidence.img
63-
evidence.img: Linux rev 1.0 ext4 filesystem data, UUID=1031571c-f398-4bfb-a414-b82b280cf299 (extents) (64bit) (large files) (huge files)
91+
# Identify partitions
92+
fdisk -l disk.img
93+
94+
# Attach the image to a network block device (does not modify the file)
95+
sudo modprobe nbd max_part=16
96+
sudo qemu-nbd --connect=/dev/nbd0 --read-only disk.img
6497

65-
#Mount it
66-
mount evidence.img /mnt
98+
# Inspect partitions
99+
lsblk /dev/nbd0 -o NAME,SIZE,TYPE,FSTYPE,LABEL,UUID
100+
101+
# Mount a partition (e.g. /dev/nbd0p2)
102+
sudo mount -o ro,uid=$(id -u) /dev/nbd0p2 /mnt
67103
```
68104

69-
### EWF
105+
Detach when finished:
106+
```bash
107+
sudo umount /mnt && sudo qemu-nbd --disconnect /dev/nbd0
108+
```
109+
110+
### EWF (E01/EWFX)
70111

71112
```bash
72-
#Get file type
73-
file evidence.E01
74-
evidence.E01: EWF/Expert Witness/EnCase image file format
75-
76-
#Transform to raw
77-
mkdir output
78-
ewfmount evidence.E01 output/
79-
file output/ewf1
80-
output/ewf1: Linux rev 1.0 ext4 filesystem data, UUID=05acca66-d042-4ab2-9e9c-be813be09b24 (needs journal recovery) (extents) (64bit) (large files) (huge files)
81-
82-
#Mount
83-
mount output/ewf1 -o ro,norecovery /mnt
113+
# 1. Mount the EWF container
114+
mkdir /mnt/ewf
115+
ewfmount evidence.E01 /mnt/ewf
116+
117+
# 2. Attach the exposed raw file via qemu-nbd (safer than loop)
118+
sudo qemu-nbd --connect=/dev/nbd1 --read-only /mnt/ewf/ewf1
119+
120+
# 3. Mount the desired partition
121+
sudo mount -o ro,norecovery /dev/nbd1p1 /mnt/evidence
84122
```
85123

86-
### ArsenalImageMounter
124+
Alternatively convert on the fly with **xmount**:
87125

88-
It's a Windows Application to mount volumes. You can download it here [https://arsenalrecon.com/downloads/](https://arsenalrecon.com/downloads/)
126+
```bash
127+
xmount --in ewf evidence.E01 --out raw /tmp/raw_mount
128+
mount -o ro /tmp/raw_mount/image.dd /mnt
129+
```
89130

90-
### Errors
131+
### LVM / BitLocker / VeraCrypt volumes
91132

92-
- **`cannot mount /dev/loop0 read-only`** in this case you need to use the flags **`-o ro,norecovery`**
93-
- **`wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.`** in this case the mount failed due as the offset of the filesystem is different than that of the disk image. You need to find the Sector size and the Start sector:
133+
After attaching the block device (loop or nbd):
94134

95135
```bash
96-
fdisk -l disk.img
97-
Disk disk.img: 102 MiB, 106954648 bytes, 208896 sectors
98-
Units: sectors of 1 * 512 = 512 bytes
99-
Sector size (logical/physical): 512 bytes / 512 bytes
100-
I/O size (minimum/optimal): 512 bytes / 512 bytes
101-
Disklabel type: dos
102-
Disk identifier: 0x00495395
103-
104-
Device Boot Start End Sectors Size Id Type
105-
disk.img1 2048 208895 206848 101M 1 FAT12
136+
# LVM
137+
sudo vgchange -ay # activate logical volumes
138+
sudo lvscan | grep "/dev/nbd0"
139+
140+
# BitLocker (dislocker)
141+
sudo dislocker -V /dev/nbd0p3 -u -- /mnt/bitlocker
142+
sudo mount -o ro /mnt/bitlocker/dislocker-file /mnt/evidence
106143
```
107144

108-
Note that sector size is **512** and start is **2048**. Then mount the image like this:
145+
### kpartx helpers
146+
147+
`kpartx` maps partitions from an image to `/dev/mapper/` automatically:
109148

110149
```bash
111-
mount disk.img /mnt -o ro,offset=$((2048*512))
150+
sudo kpartx -av disk.img # creates /dev/mapper/loop0p1, loop0p2 …
151+
mount -o ro /dev/mapper/loop0p2 /mnt
112152
```
113153

154+
### Common mount errors & fixes
114155

115-
{{#include ../../banners/hacktricks-training.md}}
156+
| Error | Typical Cause | Fix |
157+
|-------|---------------|-----|
158+
| `cannot mount /dev/loop0 read-only` | Journaled FS (ext4) not cleanly unmounted | use `-o ro,norecovery` |
159+
| `bad superblock …` | Wrong offset or damaged FS | calculate offset (`sector*size`) or run `fsck -n` on a copy |
160+
| `mount: unknown filesystem type 'LVM2_member'` | LVM container | activate volume group with `vgchange -ay` |
161+
162+
### Clean-up
116163

164+
Remember to **umount** and **disconnect** loop/nbd devices to avoid leaving dangling mappings that can corrupt further work:
117165

166+
```bash
167+
umount -Rl /mnt/evidence
168+
kpartx -dv /dev/loop0 # or qemu-nbd --disconnect /dev/nbd0
169+
```
118170

171+
172+
## References
173+
174+
- AFF4 imaging tool announcement & specification: https://github.com/aff4/aff4
175+
- qemu-nbd manual page (mounting disk images safely): https://manpages.debian.org/qemu-system-common/qemu-nbd.1.en.html
176+
177+
{{#include ../../banners/hacktricks-training.md}}

src/mobile-pentesting/android-app-pentesting/android-task-hijacking.md

Lines changed: 84 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,89 @@ Here's a quick breakdown of activity transitions:
1515

1616
![https://developer.android.com/images/fundamentals/diagram_backstack.png](<../../images/image (698).png>)
1717

18-
## Task affinity attack
19-
20-
### Overview of Task Affinity and Launch Modes
21-
22-
In Android applications, **task affinity** specifies an activity's preferred task, aligning typically with the app's package name. This setup is instrumental in crafting a proof-of-concept (PoC) app for demonstrating the attack.
23-
24-
### Launch Modes
25-
26-
The `launchMode` attribute directs the handling of activity instances within tasks. The **singleTask** mode is pivotal for this attack, dictating three scenarios based on the existing activity instances and task affinity matches. The exploit hinges on the ability of an attacker's app to mimic the target app's task affinity, misleading the Android system into launching the attacker's app instead of the intended target.
27-
28-
### Detailed Attack Steps
29-
30-
1. **Malicious App Installation**: The victim installs the attacker's app on their device.
31-
2. **Initial Activation**: The victim first opens the malicious app, setting up the device for the attack.
32-
3. **Target App Launch Attempt**: The victim attempts to open the target app.
33-
4. **Hijack Execution**: At some point the app tries to open the **singleTask** view. Due to the matching task affinity, the malicious app is launched in place of the target app.
34-
5. **Deception**: The malicious app presents a fake login screen resembling the target app, tricking the user into entering sensitive information.
35-
36-
> [!TIP]
37-
> Note that for this attack to work the vulnerable view **doesn't need to have exported to true** nor it needs to be the Main activity.
38-
39-
For a practical implementation of this attack, refer to the Task Hijacking Strandhogg repository on GitHub: [Task Hijacking Strandhogg](https://github.com/az0mb13/Task_Hijacking_Strandhogg).
40-
41-
### Prevention Measures
42-
43-
To prevent such attacks, developers can:
44-
- Set **`**taskAffinity`** of the **singleTask** view to an empty string (`android:taskAffinity=""`)
45-
- Opt for the **`singleInstance`** launch mode, ensuring their app's isolation from others.
46-
- Customize the **`onBackPressed()`** function offers additional protection against task hijacking.
47-
48-
## **References**
49-
50-
- [**https://blog.dixitaditya.com/android-task-hijacking/**](https://blog.dixitaditya.com/android-task-hijacking/)
51-
- [**https://blog.takemyhand.xyz/2021/02/android-task-hijacking-with.html**](https://blog.takemyhand.xyz/2021/02/android-task-hijacking-with.html)
18+
---
19+
20+
## Task affinity attacks
21+
22+
`taskAffinity` tells Android which task an `Activity` would *prefer* to belong to. When two activities share the same affinity **Android is allowed to merge them inside the same back-stack even if they come from different APKs**.
23+
24+
If an attacker can place a malicious activity at the **root** of that stack, every time the victim opens the legitimate application the malicious UI will be the first thing the user sees – perfect for phishing or abusive permission requests.
25+
26+
The attack surface is wider than many developers think because **every activity automatically inherits an affinity equal to the application package name** (unless the developer sets `android:taskAffinity=""`). Therefore *doing nothing* already leaves the app open to task hijacking on Android versions prior to 11.
27+
28+
### Classic "singleTask / StrandHogg" scenario
29+
30+
1. The attacker declares an activity with:
31+
```xml
32+
<activity android:name=".EvilActivity"
33+
android:exported="true"
34+
android:taskAffinity="com.victim.package"
35+
android:launchMode="singleTask" >
36+
<intent-filter>
37+
<action android:name="android.intent.action.MAIN"/>
38+
<category android:name="android.intent.category.LAUNCHER"/>
39+
</intent-filter>
40+
</activity>
41+
```
42+
2. The malicious app is started once so that the task (with the spoofed affinity) exists in recent tasks.
43+
3. When the user later opens the real application, Android finds there is already a task whose **root affinity matches the package** and just brings that task to the foreground.
44+
4. The attacker’s UI is shown first.
45+
46+
### Default–Affinity (no `singleTask`) variant – Caller ID case study
47+
48+
The vulnerability reported in the **Caller ID (caller.id.phone.number.block)** application shows that the attack *also* works against the default `standard` launch mode:
49+
50+
1. Attacker application creates a fake root activity and immediately hides itself:
51+
```kotlin
52+
class HackActivity : AppCompatActivity() {
53+
override fun onCreate(savedInstanceState: Bundle?) {
54+
super.onCreate(savedInstanceState)
55+
moveTaskToBack(true) // keep the task in recents but out of sight
56+
}
57+
}
58+
```
59+
2. The manifest only needs to copy the victim package into `taskAffinity`:
60+
```xml
61+
<activity android:name=".HackActivity"
62+
android:exported="true"
63+
android:taskAffinity="com.caller.id.phone.number.block" >
64+
<intent-filter>
65+
<action android:name="android.intent.action.MAIN"/>
66+
<category android:name="android.intent.category.LAUNCHER"/>
67+
</intent-filter>
68+
</activity>
69+
```
70+
3. As soon as the user installs and opens the malicious app **once**, a task whose affinity equals the victim package exists (but sits in the background).
71+
4. When the real Caller ID application is launched, Android re-uses that task and brings `HackActivity` to the foreground → phishing window/permission abuse.
72+
73+
> NOTE: Starting with **Android 11 (API 30)** the system does *not* place two packages that are not part of the same UID into the same task by default, mitigating this particular variant. Older versions remain vulnerable.
74+
75+
---
76+
77+
## Detection & Exploitation checklist
78+
79+
1. Pull `AndroidManifest.xml` from the target APK and check that each `<activity>` (or the global `<application>` element) contains `android:taskAffinity=""` (empty) **or** a customised value.
80+
2. If not, craft a malicious app:
81+
- `android:taskAffinity` = victim package name.
82+
- Provide a `MAIN/LAUNCHER` intent so the user can open it once.
83+
- Optionally call `moveTaskToBack(true)` to hide immediately.
84+
3. Let the victim open their legitimate application → hijack.
85+
86+
## Mitigation
87+
88+
Developers should:
89+
90+
* Explicitly set `android:taskAffinity=""` at the `<application>` level (recommended) **or** give each activity a unique, private affinity.
91+
* For highly sensitive screens, combine the above with `android:launchMode="singleInstance"` or modern [`setLaunchMode`](https://developer.android.com/reference/android/content/pm/ActivityInfo#launchMode) protections.
92+
* Upgrade the app’s `targetSdkVersion` and enforce **Android 11** behavioural changes where tasks are not shared across packages by default.
93+
94+
---
95+
96+
## References
97+
98+
- [https://blog.dixitaditya.com/android-task-hijacking/](https://blog.dixitaditya.com/android-task-hijacking/)
99+
- [https://blog.takemyhand.xyz/2021/02/android-task-hijacking-with.html](https://blog.takemyhand.xyz/2021/02/android-task-hijacking-with.html)
100+
- [Android Manifest Misconfiguration Leading to Task Hijacking in Caller ID app](https://github.com/KMov-g/androidapps/blob/main/caller.id.phone.number.block.md)
101+
- [https://medium.com/mobile-app-development-publication/the-risk-of-android-strandhogg-security-issue-and-how-it-can-be-mitigated-80d2ddb4af06](https://medium.com/mobile-app-development-publication/the-risk-of-android-strandhogg-security-issue-and-how-it-can-be-mitigated-80d2ddb4af06)
52102

53103
{{#include ../../banners/hacktricks-training.md}}
54-
55-
56-

0 commit comments

Comments
 (0)