Month: October 2023

How to patch Android app to sniff its HTTPS traffic with self-signed certificate

Nice way to sniff communication between Android application and a server to implement MITM. This way we can get the firmware downloaded from a vendor during the firmware update process.

https://gist.github.com/unoexperto/80694ccaed6dadc304ad5b8196cbbd2c#how-to-patch-android-app-to-sniff-its-https-traffic-with-self-signed-certificate

Easy and simple way to create screencast GIFs on Linux

You can use the Peek program to record and create a GIF for you.

First install Peek the usual way:

$ sudo apt install peek

Run the Peek application and resize it to be just cover the window or area you want to record.

Then press Record as GIF!

You can reduce the size of your GIF using the gifsicle command:

$ gifsicle -i original.gif -O3 --colors 256 -o optimized.gi

You can reduce even further the final size case you are recording terminal sequence tutorials where we don’t have many colors (normally black and green in my case).

$ gifsicle -i original.gif -O3 –colors 16 -o optimized.gif

Fixing NuttX compilation errors to Meadow F7Micro

These were the errors I was receiving:

CC: chip/stm32_allocateheap.c chip/stm32_allocateheap.c:122:6: warning: #warning "CONFIG_HEAP2_BASE or CONFIG_HEAP2_SIZE are zero. No HEAP2 enabled!" [-Wcpp]
122 | # warning "CONFIG_HEAP2_BASE or CONFIG_HEAP2_SIZE are zero. No HEAP2 enabled!"
| ^~~
CC: stm32_userspace.c stm32_userspace.c:47:4: error: #error "CONFIG_NUTTX_USERSPACE must be 0x08040000 to match memory.ld"
47 | # error "CONFIG_NUTTX_USERSPACE must be 0x08040000 to match memory.ld"
| ^~~~~
make[1]: *** [Makefile:54: stm32_userspace.o] Error 1
make: *** [tools/Unix.mk:526: nuttx] Error 2

The HEAP2_BASE was fixed this defining:

CONFIG_HEAP2_BASE=0xc0000000
CONFIG_HEAP2_SIZE=33554432

About the CONFIG_NUTTX_USERSPACE I defined it to 0x08040000 as suggested, although in the previous NuttX kernel used on Meadow it was defined to 0x08040200.

CONFIG_NUTTX_USERSPACE=0x08040000

NuttX on STM32F401 crashing

I was porting NuttX to a STM32F401 board and I was getting this error:

ABCDF
mm_initialize: Heap: start=0x200017b0 size=92240
mm_addregion: Region 1: base=0x200017b0 size=92240
irq_unexpected_isr: ERROR irq: 3
up_assert: Assertion failed at file:irq/irq_unexpectedisr.c line: 65
up_registerdump: R0: 80000000 200017b8 20017ff8 00016840 200011d4 200017b0 20018000 00016840
up_registerdump: R8: 00000000 00000000 00000000 00000000 00000000 20001770 08003c67 08003c90
up_registerdump: xPSR: 21000200 PRIMASK: 00000000 CONTROL: 00000000
up_registerdump: EXC_RETURN: fffffff9
up_dumpstate: sp:     20000bb0
up_dumpstate: IRQ stack:
up_dumpstate:   base: 20000c00
up_dumpstate:   size: 00000800
up_stackdump: 20000ba0: 20000bb0 00000400 20000c00 08000cdb 00000000 00000000 00000000 00000000
up_stackdump: 20000bc0: 20001770 08003c67 08003c90 0800e8a4 00000000 0800159d 08001581 08001561
up_stackdump: 20000be0: 00000000 080012c1 00000000 20001724 200017b0 20018000 00016840 08000df7
up_dumpstate: sp:     20001770
up_dumpstate: User stack:
up_dumpstate:   base: 200017ac
up_dumpstate:   size: 00000400
up_stackdump: 20001760: 00000000 08003c67 08003c90 21000200 00000001 200017b0 00016850 20000ccc
up_stackdump: 20001780: 20000ccc 20000c04 00000003 20000d9c 080013cb 200017b0 00016850 00000000
up_stackdump: 200017a0: 0800020d 00000000 ffffffff 00000000 00000008 80000000 00016840 00000008

The first thing that catch my attention was the heap size=92240! This microcontroller has 64KB, so it is not possible to have a heap memory bigger than 64KB.

I noticed the CONFIG_RAM_SIZE was defined with high value (96KB) then I changed it to:

CONFIG_RAM_SIZE=65536

But it took no effect!

Then I changed the nuttx/boards/arm/stm32/nucleo-f4x1re/scripts/f401re.ld to the right values:

MEMORY
{
  flash (rx) : ORIGIN = 0x08000000, LENGTH = 128K
  sram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
}

This not luck!! What a challenge!?

Then I decided to search where mm_initialize and mm_addregion are called inside arch/arm/src/stm32 and found some important information at stm32_allocateheap.c

/* Most members of both the STM32F20xxx and STM32F40xxx families have 128Kib
 * in two banks:
 *
 *   1) 112KiB of System SRAM beginning at address 0x2000:0000
 *   2)  16KiB of System SRAM beginning at address 0x2001:c000
 *
 * The STM32F401 family is an exception and has only 64KiB or 96Kib total on one
 * bank:

And:

/* The STM32 F2 and the STM32 F401/F411 have no CCM SRAM */

And finally:

#  if defined(CONFIG_STM32_STM32F401xBC)
#    define SRAM1_END 0x20010000
#  elif defined(CONFIG_STM32_STM32F401xDE)
#    define SRAM1_END 0x20018000

Yes, that was the issue: my board is powered by STM32F401RCT6 but my .config was:

# CONFIG_STM32_STM32F401xBC is not set
CONFIG_STM32_STM32F401xDE=y

After changing it to MCU to STM32F401RC I saw it in my .config:

CONFIG_STM32_STM32F401xBC=y
# CONFIG_STM32_STM32F401xDE is not set

And now everything worked as expected!

NuttShell (NSH) NuttX-12.3.0-RC0
nsh> ?
help usage:  help [-v] [<cmd>]

    .           cd          exit        mount       source      uptime      
    [           cp          false       mv          test        usleep      
    ?           cmp         help        printf      time        xd          
    alias       dirname     hexdump     pwd         true        
    unalias     dd          kill        rm          truncate    
    basename    dmesg       ls          rmdir       uname       
    break       echo        mkdir       set         umount      
    cat         exec        mkrd        sleep       unset       

Builtin Apps:
    nsh    sh     
nsh> uname -a
NuttX 12.3.0-RC0 6cad7e9582-dirty Oct 12 2023 15:36:23 arm stm32f401rc-rs485
nsh>

Note: I found a user that faced similar issue: https://nuttx.yahoogroups.narkive.com/1j3cuqjV/stm32f410-support but probably he never figured out this issue (he never replied later and I never saw he again in the NuttX community). The only reason because I succeed is because I never give up and I investigate deeper!

Meadow version mismatch, how to fix?

Today I compiled the Meadow version 1.3.5.5 and when trying to deploy an app I got this error:

Meadow StdInfo: Mono will not start - version mismatch: Meadow.OS version 1.3.4.0, Mono version 1.3.5.5, Mono disabled
Meadow StdInfo: Mono is disabled
Meadow StdInfo: Mono has been enabled - restarting Meadow

Connecting to Meadow on /dev/ttyACM0

An unknown request value of '0x4D00' was received.
Meadow StdInfo: Mono is disabled
Meadow StdInfo: Mono has been enabled - restarting Meadow

Connecting to Meadow on /dev/ttyACM0

An unknown request value of '0x4D00' was received.
Meadow StdInfo: Mono is disabled
Meadow StdInfo: Mono has been enabled - restarting Meadow

Connecting to Meadow on /dev/ttyACM0

An unknown request value of '0x4D00' was received.
Meadow StdInfo: Mono is disabled
Meadow StdInfo: Mono has been enabled - restarting Meadow

Connecting to Meadow on /dev/ttyACM0

An unknown request value of '0x4D00' was received.
Meadow StdInfo: Mono is disabled
Meadow StdInfo: Mono has been enabled - restarting Meadow

Connecting to Meadow on /dev/ttyACM0

This error was happening because I don’t have the version directory 1.3.5.5/ at “~/.local/share/WildernessLabs/Firmware/”. Let’s fix it:

$ cd ~/.local/share/WildernessLabs/Firmware
$ cp -a 1.3.4.0 1.3.5.5
$ cd ~/Meadow/nuttx/
$ cp Meadow.OS.* ~/.local/share/WildernessLabs/Firmware/1.3.5.5/

Now I can deploy the application correctly:

$ meadow app deploy -f bin/Debug/netstandard2.1/App.dll -s /dev/ttyACM0

Connecting to Meadow on /dev/ttyACM0

Downloading version file for Meadow OS 1.3.5.5

Error downloading file from https://s3-us-west-2.amazonaws.com/downloads.wildernesslabs.co/Meadow_Beta/1.3.5.5.json
System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Meadow.CLI.Core.DownloadManager.DownloadFile(Uri uri, CancellationToken cancellationToken) in D:\a\Meadow.CLI\Meadow.CLI\main\Meadow.CLI.Core\Managers\DownloadManager.cs:line 316
Meadow OS 1.3.5.5 cannot be downloaded or is not available
Meadow StdInfo: Mono is disabled
Meadow StdInfo: dev/
Meadow StdInfo: little0 [block]
Meadow StdInfo: little0p0 [block]
Meadow StdInfo: monostderr [char]
Meadow StdInfo: monostdout [char]
Meadow StdInfo: mtdblock0 [block]
Meadow StdInfo: null [char]
Meadow StdInfo: nxupd [char]
Meadow StdInfo: pwm0 [char]
Meadow StdInfo: ramlog [char]
Meadow StdInfo: random [char]
Meadow StdInfo: ttyACM0 [char]
Meadow StdInfo: ttyS0 [char]
Meadow StdInfo: ttyS1 [char]
Meadow StdInfo: ttyS2 [char]
Meadow StdInfo: tun [char]
Meadow StdInfo: upd [char]
Meadow StdInfo: urandom [char]
Meadow StdInfo: usrsock [char]
Meadow StdInfo: meadow0/
Meadow StdInfo: ./
Meadow StdInfo: ../
Meadow StdInfo: App.pdb [file]
Meadow StdInfo: app.config.yaml [file]
Meadow StdInfo: App.deps.json [file]
Meadow StdInfo: meadow.config.yaml [file]
Meadow StdInfo: Meadow.Contracts.dll [file]
Meadow StdInfo: Meadow.dll [file]
Meadow StdInfo: Meadow.F7.dll [file]
Meadow StdInfo: Meadow.Logging.dll [file]
Meadow StdInfo: Meadow.Units.dll [file]
Meadow StdInfo: Microsoft.Bcl.AsyncInterfaces.dll [file]
Meadow StdInfo: Mono.Security.dll [file]
Meadow StdInfo: MQTTnet.dll [file]
Meadow StdInfo: mscorlib.dll [file]
Meadow StdInfo: mscorlib.pdb [file]
Meadow StdInfo: netstandard.dll [file]
Meadow StdInfo: System.Buffers.dll [file]
Meadow StdInfo: System.Configuration.dll [file]
Meadow StdInfo: System.Core.dll [file]
Meadow StdInfo: System.Core.pdb [file]
Meadow StdInfo: System.dll [file]
Meadow StdInfo: System.IO.Compression.dll [file]
Meadow StdInfo: System.IO.Compression.FileSystem.dll [file]
Meadow StdInfo: System.Memory.dll [file]
Meadow StdInfo: System.Net.Http.dll [file]
Meadow StdInfo: System.Numerics.dll [file]
Meadow StdInfo: System.Numerics.Vectors.dll [file]
Meadow StdInfo: System.pdb [file]
Meadow StdInfo: System.Runtime.CompilerServices.Unsafe.dll [file]
Meadow StdInfo: System.Text.Encodings.Web.dll [file]
Meadow StdInfo: System.Text.Json.dll [file]
Meadow StdInfo: System.Web.dll [file]
Meadow StdInfo: System.Xml.dll [file]
Meadow StdInfo: System.Threading.Tasks.Extensions.dll [file]
Meadow StdInfo: Cache/
Meadow StdInfo: ./
Meadow StdInfo: ../
Meadow StdInfo: Data/
Meadow StdInfo: ./
Meadow StdInfo: ../
Meadow StdInfo: Documents/
Meadow StdInfo: ./
Meadow StdInfo: ../
Meadow StdInfo: Temp/
Meadow StdInfo: ./
Meadow StdInfo: ../
Meadow StdInfo: update-store/
Meadow StdInfo: ./
Meadow StdInfo: ../
Meadow StdInfo: App.dll [file]
Meadow StdInfo: Microsoft.Extensions.Configuration.FileExtensions.dll [file]
Meadow StdInfo: Microsoft.Extensions.FileSystemGlobbing.dll [file]
Meadow StdInfo: Microsoft.Extensions.Configuration.Json.dll [file]
Meadow StdInfo: NetEscapades.Configuration.Yaml.dll [file]
Meadow StdInfo: Microsoft.Extensions.Primitives.dll [file]
Meadow StdInfo: YamlDotNet.dll [file]
Meadow StdInfo: Microsoft.Extensions.FileProviders.Physical.dll [file]
Meadow StdInfo: Microsoft.Extensions.Configuration.dll [file]
Meadow StdInfo: Microsoft.Extensions.FileProviders.Abstractions.dll [file]
Meadow StdInfo: Microsoft.Extensions.Configuration.Abstractions.dll [file]
Meadow StdInfo: meadow.log [file]
Meadow StdInfo: dns.conf [file]
Meadow StdInfo: Meadow.OS.Runtime.bin [file]
Meadow StdInfo: var/
Meadow StdInfo: mqueue/
Meadow StdInfo: Esp32Events [char]
Meadow StdInfo: Esp32Requests [char]
Meadow StdInfo: IncomingEvents [char]
Found App.pdb (CRC: 69773591)

Found app.config.yaml (CRC: 368866788)

Found App.deps.json (CRC: 2158837883)

Found meadow.config.yaml (CRC: 1124400009)

Found Meadow.Contracts.dll (CRC: 2846447947)

Found Meadow.dll (CRC: 2719373228)

Found Meadow.F7.dll (CRC: 1442057766)

Found Meadow.Logging.dll (CRC: 824344321)

Found Meadow.Units.dll (CRC: 4140401653)

Found Microsoft.Bcl.AsyncInterfaces.dll (CRC: 3215379713)

Found Mono.Security.dll (CRC: 1686271713)

Found MQTTnet.dll (CRC: 3704087888)

Found mscorlib.dll (CRC: 1808161920)

Found mscorlib.pdb (CRC: 4277026598)

Found netstandard.dll (CRC: 1317547153)

Found System.Buffers.dll (CRC: 2270003332)

Found System.Configuration.dll (CRC: 3551228838)

Found System.Core.dll (CRC: 973293428)

Found System.Core.pdb (CRC: 3045662084)

Found System.dll (CRC: 1784089163)

Found System.IO.Compression.dll (CRC: 108922931)

Found System.IO.Compression.FileSystem.dll (CRC: 3696561774)

Found System.Memory.dll (CRC: 1315600087)

Found System.Net.Http.dll (CRC: 2789588721)

Found System.Numerics.dll (CRC: 262948716)

Found System.Numerics.Vectors.dll (CRC: 1770273314)

Found System.pdb (CRC: 3047866524)

Found System.Runtime.CompilerServices.Unsafe.dll (CRC: 471205693)

Found System.Text.Encodings.Web.dll (CRC: 2255902349)

Found System.Text.Json.dll (CRC: 1859305368)

Found System.Web.dll (CRC: 873630947)

Found System.Xml.dll (CRC: 433901453)

Found System.Threading.Tasks.Extensions.dll (CRC: 2160723354)

Found App.dll (CRC: 3454494094)

Found Microsoft.Extensions.Configuration.FileExtensions.dll (CRC: 4121043609)

Found Microsoft.Extensions.FileSystemGlobbing.dll (CRC: 2950879595)

Found Microsoft.Extensions.Configuration.Json.dll (CRC: 1836327059)

Found NetEscapades.Configuration.Yaml.dll (CRC: 2894847578)

Found Microsoft.Extensions.Primitives.dll (CRC: 163906323)

Found YamlDotNet.dll (CRC: 1259838021)

Found Microsoft.Extensions.FileProviders.Physical.dll (CRC: 338685548)

Found Microsoft.Extensions.Configuration.dll (CRC: 2526625974)

Found Microsoft.Extensions.FileProviders.Abstractions.dll (CRC: 2670091038)

Found Microsoft.Extensions.Configuration.Abstractions.dll (CRC: 33053645)

Found meadow.log (CRC: 2391922906)

Found dns.conf (CRC: 3162743132)

Found Meadow.OS.Runtime.bin (CRC: 4177118538)

Trimming assemblies to reduce size (may take several seconds)...
Trimming complete
Meadow StdInfo: Meadow successfully deleted '/meadow0/meadow.log'
Removing file: FileData { FullPath = /meadow0/meadow.log, FileName = meadow.log, Crc = 2391922906, FileSize = 152 }

Meadow StdInfo: Meadow successfully deleted '/meadow0/dns.conf'
Removing file: FileData { FullPath = /meadow0/dns.conf, FileName = dns.conf, Crc = 3162743132, FileSize = 83 }

Meadow StdInfo: Meadow successfully deleted '/meadow0/Meadow.OS.Runtime.bin'
Removing file: FileData { FullPath = /meadow0/Meadow.OS.Runtime.bin, FileName = Meadow.OS.Runtime.bin, Crc = 4177118538, FileSize = 3145728 }

Skipping file (hash match): App.dll

Skipping file (hash match): App.pdb

Skipping file (hash match): app.config.yaml

Skipping file (hash match): App.deps.json


Sending file: /comum/workspace/Consultancy/WildernessLabs/MeadowNew/Test/bin/Debug/netstandard2.1/wifi.config.yaml

Starting File Transfer... 
 
Meadow StdInfo: Download of 'wifi.config.yaml' success (checksums calculated:0x019042D2, expected:0x019042D2)

Transfer Complete, wrote 604 bytes to Meadow

Skipping file (hash match): meadow.config.yaml

Skipping file (hash match): System.Memory.dll

Skipping file (hash match): Microsoft.Extensions.Configuration.FileExtensions.dll

Skipping file (hash match): mscorlib.pdb

Skipping file (hash match): Microsoft.Extensions.FileSystemGlobbing.dll

Skipping file (hash match): System.Text.Encodings.Web.dll

Skipping file (hash match): System.pdb

Skipping file (hash match): System.Configuration.dll

Skipping file (hash match): Microsoft.Extensions.Configuration.Json.dll

Skipping file (hash match): NetEscapades.Configuration.Yaml.dll

Skipping file (hash match): Meadow.Contracts.dll

Skipping file (hash match): Microsoft.Extensions.Primitives.dll

Skipping file (hash match): Meadow.Units.dll

Skipping file (hash match): System.Web.dll

Skipping file (hash match): Meadow.F7.dll

Skipping file (hash match): System.Text.Json.dll

Skipping file (hash match): System.Xml.dll

Skipping file (hash match): System.Core.dll

Skipping file (hash match): System.dll

Skipping file (hash match): System.Net.Http.dll

Skipping file (hash match): Meadow.dll

Skipping file (hash match): YamlDotNet.dll

Skipping file (hash match): MQTTnet.dll

Skipping file (hash match): System.Buffers.dll

Skipping file (hash match): System.IO.Compression.FileSystem.dll

Skipping file (hash match): Meadow.Logging.dll

Skipping file (hash match): System.Core.pdb

Skipping file (hash match): System.Numerics.dll

Skipping file (hash match): Microsoft.Bcl.AsyncInterfaces.dll

Skipping file (hash match): Microsoft.Extensions.FileProviders.Physical.dll

Skipping file (hash match): netstandard.dll

Skipping file (hash match): System.IO.Compression.dll

Skipping file (hash match): Microsoft.Extensions.Configuration.dll

Skipping file (hash match): Microsoft.Extensions.FileProviders.Abstractions.dll

Skipping file (hash match): mscorlib.dll

Skipping file (hash match): Microsoft.Extensions.Configuration.Abstractions.dll

Skipping file (hash match): Mono.Security.dll

Skipping file (hash match): System.Runtime.CompilerServices.Unsafe.dll

Skipping file (hash match): System.Numerics.Vectors.dll

Skipping file (hash match): System.Threading.Tasks.Extensions.dll


App.dll deploy complete!

Meadow StdInfo: Mono is disabled
Meadow StdInfo: Mono has been enabled - restarting Meadow

Connecting to Meadow on /dev/ttyACM0

Meadow StdInfo: Meadow successfully started MONO
Meadow StdInfo: Mono is enabled
Done!