Skip to main content
Blah
Source Link
Chris Davies
  • 128.4k
  • 16
  • 179
  • 324

Yes, you can do this. I would use something like sed to perform the gross changes and then xxd to give me an editable file that would let me replace the remaining unwanted characters with NULs.

Example

# Arbitrary preparation of a file containing NUL characters
echo 'This is a file containing abcde.domain.com#as a domain#' | tr '#' '\0' >file.dat

hex file.dat
   0000 54 68 69 73 20 69 73 20  61 20 66 69 6c 65 20 63  This is  a file c
   0010 6f 6e 74 61 69 6e 69 6e  67 20 61 62 63 64 65 2e  ontainin g abcde.
   0020 64 6f 6d 61 69 6e 2e 63  6f 6d 00 61 73 20 61 20  domain.c om.as a
   0030 64 6f 6d 61 69 6e 00                              domain.

Notice the two NUL (00) codes.

Now let's modify file.dat, replacing abcde.domain.com with the shorter but padded 75.4.60.8:

sed 's/abcde.domain.com/75.4.60.8#######/g' file.dat | xxd >file.xxd
vi file.xxd

Inside the editor, replace the relevant # characters (hex 23) with NUL (hex 00). Then convert the hex dump back into the corresponding data file:

xxd -r file.xxd >file.new

Job done.

However, if you're changing the destination for a web service, bear in mind that many web servers use the target hostname as part of the selector for choosing the appropriate website. So referencing (say) contoso.com is not necessarily the same as (say) 203.0.113.1. You might be better fixing up /etc/hosts or providing an RPZ overlay in your local DNS server.

Yes, you can do this. I would use something like sed to perform the gross changes and then xxd to give me an editable file that would let me replace the remaining unwanted characters with NULs.

Example

# Arbitrary preparation of a file containing NUL characters
echo 'This is a file containing abcde.domain.com#as a domain#' | tr '#' '\0' >file.dat

hex file.dat
   0000 54 68 69 73 20 69 73 20  61 20 66 69 6c 65 20 63  This is  a file c
   0010 6f 6e 74 61 69 6e 69 6e  67 20 61 62 63 64 65 2e  ontainin g abcde.
   0020 64 6f 6d 61 69 6e 2e 63  6f 6d 00 61 73 20 61 20  domain.c om.as a
   0030 64 6f 6d 61 69 6e 00                              domain.

Notice the two NUL (00) codes.

Now let's modify file.dat, replacing abcde.domain.com with the shorter but padded 75.4.60.8:

sed 's/abcde.domain.com/75.4.60.8#######/g' file.dat | xxd >file.xxd
vi file.xxd

Inside the editor, replace the relevant # characters (hex 23) with NUL (hex 00)

xxd -r file.xxd >file.new

Job done.

However, if you're changing the destination for a web service, bear in mind that many web servers use the target hostname as part of the selector for choosing the appropriate website. So referencing (say) contoso.com is not necessarily the same as (say) 203.0.113.1. You might be better fixing up /etc/hosts or providing an overlay in your local DNS server.

Yes, you can do this. I would use something like sed to perform the gross changes and then xxd to give me an editable file that would let me replace the remaining unwanted characters with NULs.

Example

# Arbitrary preparation of a file containing NUL characters
echo 'This is a file containing abcde.domain.com#as a domain#' | tr '#' '\0' >file.dat

hex file.dat
   0000 54 68 69 73 20 69 73 20  61 20 66 69 6c 65 20 63  This is  a file c
   0010 6f 6e 74 61 69 6e 69 6e  67 20 61 62 63 64 65 2e  ontainin g abcde.
   0020 64 6f 6d 61 69 6e 2e 63  6f 6d 00 61 73 20 61 20  domain.c om.as a
   0030 64 6f 6d 61 69 6e 00                              domain.

Notice the two NUL (00) codes.

Now let's modify file.dat, replacing abcde.domain.com with the shorter but padded 75.4.60.8:

sed 's/abcde.domain.com/75.4.60.8#######/g' file.dat | xxd >file.xxd
vi file.xxd

Inside the editor, replace the relevant # characters (hex 23) with NUL (hex 00). Then convert the hex dump back into the corresponding data file:

xxd -r file.xxd >file.new

Job done.

However, if you're changing the destination for a web service, bear in mind that many web servers use the target hostname as part of the selector for choosing the appropriate website. So referencing (say) contoso.com is not necessarily the same as (say) 203.0.113.1. You might be better fixing up /etc/hosts or providing an RPZ overlay in your local DNS server.

Source Link
Chris Davies
  • 128.4k
  • 16
  • 179
  • 324

Yes, you can do this. I would use something like sed to perform the gross changes and then xxd to give me an editable file that would let me replace the remaining unwanted characters with NULs.

Example

# Arbitrary preparation of a file containing NUL characters
echo 'This is a file containing abcde.domain.com#as a domain#' | tr '#' '\0' >file.dat

hex file.dat
   0000 54 68 69 73 20 69 73 20  61 20 66 69 6c 65 20 63  This is  a file c
   0010 6f 6e 74 61 69 6e 69 6e  67 20 61 62 63 64 65 2e  ontainin g abcde.
   0020 64 6f 6d 61 69 6e 2e 63  6f 6d 00 61 73 20 61 20  domain.c om.as a
   0030 64 6f 6d 61 69 6e 00                              domain.

Notice the two NUL (00) codes.

Now let's modify file.dat, replacing abcde.domain.com with the shorter but padded 75.4.60.8:

sed 's/abcde.domain.com/75.4.60.8#######/g' file.dat | xxd >file.xxd
vi file.xxd

Inside the editor, replace the relevant # characters (hex 23) with NUL (hex 00)

xxd -r file.xxd >file.new

Job done.

However, if you're changing the destination for a web service, bear in mind that many web servers use the target hostname as part of the selector for choosing the appropriate website. So referencing (say) contoso.com is not necessarily the same as (say) 203.0.113.1. You might be better fixing up /etc/hosts or providing an overlay in your local DNS server.