понедељак, 8. април 2024.

Kopiranje memorije pomoću md.b

 Dakle dobio sam DVR čiji je telnet zaštićen llozinkom, a kad se uđe na tty posle određenog vremena DVR se resetuje pa je nephodno dump-vati određen dio memorije

i sačuvati je u text-ualnom fajlu pa naknadno konverotvati u binarni

 

 

Evo je skripta koja dumpuje porciju memorije u fajl





#!/usr/bin/expect

# Replace with the actual serial port of your device (e.g., /dev/ttyACM0)
set serial_port "/dev/ttyACM0"

# Replace with the starting memory address
set start_address 0xe1000000

# Replace with the size of each chunk
set chunk_size 0x3E00

# Replace with the target address to stop at
set stop_address 0xE100BA00

# Open a connection to the serial port
spawn cu -l $serial_port -s 115200

# Expect the message to stop autoboot
expect "Hit any key to stop autoboot:"
send "\r"
#after 2000
# Set the initial address
set current_address $start_address

# Dump memory in chunks
while {$current_address < $stop_address} {
    # Send the md command to the bootloader for the current chunk
    send "md.b $current_address $chunk_size\r"

    # Wait for the bootloader's response
    expect "Hit any key to stop autoboot:"
    send "\r"

    # Send any key to continue (press Enter)
    #send "\r"
    # Update the current address for the next chunk
    # set current_address [expr {$current_address + $chunk_size}]
    set current_address [format %x [expr {$current_address + $chunk_size}]]
}

# Close the connection
#send "\x03"  ;# Send Ctrl+C to stop autoboot if needed
send "exit\r"
expect eof
  
A i evoga ga program koji konvertuje text u binarni
  
  #!/usr/bin/env python3

#    Small hackish script to convert an U-Boot memdump to a binary image
#
#    Copyright (C) 2015  Simon Baatz
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import sys
import io

BYTES_IN_LINE = 0x10 # Number of bytes to expect in each line

c_addr = None
hex_to_ch = {}

ascii_stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='ascii', errors='strict')

for line in ascii_stdin:
    line = line[:-1] # Strip the linefeed (we can't strip all white
                     # space here, think of a line of 0x20s)
    data, ascii_data = line.split("    ", maxsplit = 1)
    straddr, strdata = data.split(maxsplit = 1)
    addr = int.from_bytes(bytes.fromhex(straddr[:-1]), byteorder = 'big')
    if c_addr != addr - BYTES_IN_LINE:
        if c_addr:
            sys.exit("Unexpected c_addr in line: '%s'" % line)
    c_addr = addr
    data = bytes.fromhex(strdata)
    if len(data) != BYTES_IN_LINE:
        sys.exit("Unexpected number of bytes in line: '%s'" % line)
    # Verify that the mapping from hex data to ASCII is consistent (sanity check for transmission errors)
    for b, c in zip(data, ascii_data):
        try:
            if hex_to_ch[b] != c:
                sys.exit("Inconsistency between hex data and ASCII data in line (or the lines before): '%s'" % line)
        except KeyError:
            hex_to_ch[b] = c
    sys.stdout.buffer.write(data)
  
  

Нема коментара:

Постави коментар