Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
This module implements Tizen's block map format, which maps non-empty blocks or block ranges from a raw image file, making it possible to quickly & efficiently flash the image to the target block device by only reading & writing the necessary blocks.
$ npm install --save blockmap
For detailed API documentation, see /doc
.
var BlockMap = require( 'blockmap' )
var blockMap = BlockMap.parse( xml )
BlockMap {
version: '2.0',
imageSize: 821752,
blockSize: 4096,
blockCount: 201,
mappedBlockCount: 117,
checksum: '44e9d58de533d5eb94f8232cff22b2e6d71b15d369c2ac2af461c63164cce324',
checksumType: 'sha256',
ranges: [{
checksum: '9eaf19215d55d23de1be1fe4bed4a95bfe620a404352fd06e782738fff58e500',
start: 0,
end: 1
}, {
checksum: 'e8a26f49a71262870f8294a73f40f122d622fd70fb82bef01c0322785e9fd6b2',
start: 3,
end: 5
},
// More ranges omitted for brevity
{
checksum: 'cb732fc3f3a0f81f6a761a534201c05549c8efe4a92630ccd24241f72d7d618c',
start: 198,
end: 199
}]
}
Render a .bmap
file from a parsed or otherwise constructed BlockMap
:
var blockMap = BlockMap.parse( value )
var xml = blockMap.toString()
Where xml
would look like the following, given the block map from above:
<?xml version="1.0" encoding="UTF-8"?>
<bmap version="2.0">
<ImageSize>821752</ImageSize>
<BlockSize>4096</BlockSize>
<BlocksCount>201</BlocksCount>
<MappedBlocksCount>117</MappedBlocksCount>
<ChecksumType>sha256</ChecksumType>
<BmapFileChecksum>44e9d58de533d5eb94f8232cff22b2e6d71b15d369c2ac2af461c63164cce324</BmapFileChecksum>
<BlockMap>
<Range chksum="9eaf19215d55d23de1be1fe4bed4a95bfe620a404352fd06e782738fff58e500">0-1</Range>
<Range chksum="e8a26f49a71262870f8294a73f40f122d622fd70fb82bef01c0322785e9fd6b2">3-5</Range>
<!-- More ranges omitted for brevity -->
<Range chksum="cb732fc3f3a0f81f6a761a534201c05549c8efe4a92630ccd24241f72d7d618c">198-199</Range>
</BlockMap>
</bmap>
NOTE: Regardless of input version, blockMap.toString()
will always
create a .bmap
in the format of the latest version (currently 2.0
).
By default, checksums for mapped ranges and the bmap file itself (only version 1.3+)
will be verified when parsing or streaming. If you need to disable verification,
pass verify: false
in the options:
// Disable verification of the bmap file checksum:
var blockMap = BlockMap.parse( bmap, { verify: false })
// Disable range checksum verification:
var blockReadStream = new BlockMap.ReadStream( '/path/to/resin-os.img', blockMap, {
verify: false,
})
// Same for filter streams:
var filterStream = new BlockMap.FilterStream( blockMap, {
verify: false,
})
Use a parsed block map to read only mapped regions:
var blockMap = BlockMap.parse( fs.readFileSync( '/path/to/resin-os.bmap' ) )
var blockReadStream = new BlockMap.ReadStream( '/path/to/resin-os.img', blockMap )
// The buffer will have two additional properties set;
// 1) buffer.address – it's block address in respect to the .bmap's block size
// 2) buffer.position – the block's offset (or address) in bytes
// Which can then be used to write only those blocks to the target:
blockReadStream.on( 'readable', function() {
var buffer = null
while( buffer = this.read() ) {
fs.writeSync( fd, buffer, 0, buffer.length, buffer.position )
}
})
blockReadStream.once( 'end', function() {
console.log( 'Read', blockReadStream.blocksRead, 'mapped blocks' )
console.log( 'Read', blockReadStream.bytesRead, 'mapped bytes' )
console.log( 'Read', blockReadStream.rangesRead, 'mapped ranges' )
})
Use a filter transform to filter out unmapped blocks from a stream:
var blockMap = BlockMap.parse( fs.readFileSync( '/path/to/resin-os.bmap' ) )
var readStream = fs.createReadStream( '/path/to/resin-os.img' )
var filterStream = new BlockMap.FilterStream( blockMap )
// The buffer will have two additional properties set;
// 1) buffer.address – it's block address in respect to the .bmap's block size
// 2) buffer.position – the block's offset (or address) in bytes
// Which can then be used to write only those blocks to the target:
filterStream.on( 'readable', function() {
var buffer = null
while( buffer = this.read() ) {
fs.writeSync( fd, buffer, 0, buffer.length, buffer.position )
}
})
// Pipe the readable stream into the block filter:
readStream.pipe( filterStream )
Use a BlockMap.ReadStream
to verify a flashed device image:
function verify( devicePath, blockMap, callback ) {
new BlockMap.ReadStream( devicePath, blockMap ).resume()
.once( 'error', callback )
.once( 'end', callback )
}
var blockMap = BlockMap.parse( fs.readFileSync( '/path/to/resin-os.bmap' ) )
verify( '/dev/rdisk4', blockMap, function( error ) {
if( error != null ) {
// The image didn't verify...
}
})
BlockMap.parse()
and blockMap.parse()
will throw when
encountering invalid input, or if the checksum doesn't verify:
try {
blockMap = BlockMap.parse( value ) // OR
blockMap.parse( value )
} catch( error ) {
// ...
}
If the error is due to a checksum mismatch,
the error will have a .checksum
and .range
property,
denoting the calculated checksum, and the range for which it occured:
var blockReadStream = new BlockMap.ReadStream( '/path/to/resin-os.img', blockMap )
blockReadStream.on( 'error', function( error ) {
if( error.checksum ) {
console.log( `Checksum mismatch for range [${error.range.start},${error.range.end}]:` )
console.log( `${error.checksum} != ${error.range.checksum}` )
}
// ...
})
v2.0.2 - 2017-11-03
FAQs
Tizen's block map format
The npm package blockmap receives a total of 2,342 weekly downloads. As such, blockmap popularity was classified as popular.
We found that blockmap demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.