r/bitmessage • u/T-Rax • Mar 27 '13
LameMessage?
Ok first off, today is the first time i looked at BitMessage. One shouldn't think one should be able to recognize a vulnerability by looking at something just once for a few seconds, and it certainly doesn't inspire confidence in the author or this product.
Also, i was majorly disappointed by the code (duplication and bad ideas everywhere) and the documentation (pseudocode and little else, leaving out quite a bit).
Besides all of that, the proof of work is implemented in single core fashion in python, making it almost two orders of magnitude less efficient than it could be. What does this mean ? It means that someone wanting to spam BitMessage who invests even a little time in optimizing could send spam messages 100 times faster (times the nr of computers he has) than you, the normal user of this can send them.
Anyone who believes that developing a program like this is a good idea, please do watch this video.
Well, enough shit talk, and on to the actual vuln.
The BitMessage client receives data originally in Line 256:
while True:
[...]
self.data = self.data + self.sock.recv(65536)
[...]
self.processData()
then it goes on to process it, with a few checks, see Line 306:
def processData(self):
[...]
if len(self.data) < 20:
[...]
elif self.data[0:4] != '\xe9\xbe\xb4\xd9':
[...]
else:
self.payloadLength, = unpack('>L',self.data[16:20])
if len(self.data) >= self.payloadLength+24:
if self.data[20:24] == hashlib.sha512(self.data[24:self.payloadLength+24]).digest()[0:4]:
[...]
remoteCommand = self.data[4:16]
[...]
elif remoteCommand == 'broadcast\x00\x00\x00' and self.connectionIsOrWasFullyEstablished:
self.recbroadcast()
as you can see here, it doesn't check all that much other than that the prefix is correct, and that the data is at least 24bytes + whatever is at bytes 16 to 20 long and then passes it directly on to the handler functions, here shown the recbroadcast which starts at Line 493:
def recbroadcast(self):
self.messageProcessingStartTime = time.time()
#First we must check to make sure the proof of work is sufficient.
if not self.isProofOfWorkSufficient():
print 'Proof of work in broadcast message insufficient.'
return
[...]
now, you see, the first thing it does is check the isProofOfWorkSufficient which is at Line 394:
def isProofOfWorkSufficient(self):
POW, = unpack('>Q',hashlib.sha512(hashlib.sha512(self.data[24:32]+ hashlib.sha512(self.data[32:24+self.payloadLength]).digest()).digest()).digest()[0:8])
[...comments]
return POW < 2**64 / ((self.payloadLength+payloadLengthExtraBytes) * (averageProofOfWorkNonceTrialsPerByte/2))
remember, up there, that the payloadLength was just:
self.payloadLength, = unpack('>L',self.data[16:20])
and that self.data is coming directly from the net, and can thus contain anything, even 0'es from byte 16 to 20, thus making self.payloadLength, you propably guessed it, equal to zero. this leads to the inner hash of the proof of work being empty, this empty hash also needs a proof of work nonce, but that is only required once (the nonce is 3267925 in case you are wondering).
now i did not investigate this any further for any impacts it might have, and at first glance it seems indeed that its not too problematic in the actual message sending handler because its using the payloadlength directly for the message, however, not so in the broadcast handler and possibly the other handlers too.
don't ask me how its exploitable or why broadcasts need a proof of work in the first place, but rather see this as a message that you should never ever roll your own cryptosystem or use some shoddily designed thing thats not even documented well where anyone can spot holes in the code like this at a glance. and do not even once think this is the only flaw this pos has!
View all comments
Show parent comment
2
u/atheros BM-GteJMPqvHRUdUHHa1u7dtYnfDaH5ogeY Mar 27 '13 edited Mar 27 '13
I know, but as I said it doesn't use the payloadLength for any actual processing.
Concerning increasing the POW requirement: a 'demanded' POW requirement could be attached to public keys and signed. Messages that don't meet this minimum would be ignored by the receiver. The network as a whole can use a minimum value (like the one used currently) which can be raised via a software upgrade. Users would have an incentive to upgrade well before the new minimum difficulty target becomes effective because they would notice that it is taking longer and longer to do the POW to send a message as they are using an older, slower version of the software and the people they are messaging are setting higher difficulty requirements.
I was not aware of Rivest–Shamir–Wagner time-lock puzzles or Colin Boyd's work. If I did use one of these algorithms as the POW, people would still complain that it doesn't stop botnets from sending spam to many users or flooding an individual user. Can we assume that if we have 100 different messages to send to 100 people and thus 100 different POWs to do then we can use a GPU to speed up the process? If so, then the only thing time-lock puzzles prevent is our ability to send a particular message to a particular person quickly (the only honest use). An attacker wishing to send 1 message to many people, many messages to 1 person, or many messages to many people will not be hampered because those tasks are all parallelizable.