Beispiel #1
0
    def calculate(self):
        all_tasks = pstasks.mac_tasks(self._config).allprocs()
        bit_tasks = []

        try:
            if self._config.PID:
                # find tasks given PIDs
                pidlist = [int(p) for p in self._config.PID.split(',')]
                bit_tasks = [t for t in all_tasks if t.p_pid in pidlist]
            else:
                # find multibit process
                name_re = re.compile("JavaApplicationS", re.I)
                bit_tasks = [
                    t for t in all_tasks if name_re.search(str(t.p_comm))
                ]
        except:
            pass

        if len(bit_tasks) == 0:
            yield (None, None)

        # scan for bitcoin addresses with yara, 34 chars, https://en.bitcoin.it/wiki/Address
        # Most Bitcoin addresses are 34 characters. They consist of random digits and uppercase
        # and lowercase letters, with the exception that the uppercase letter "O", uppercase
        # letter "I", lowercase letter "l", and the number "0" are never used to prevent visual ambiguity.
        bit_addrs = []
        addr_rule = yara.compile(sources={
            'n':
            'rule r1 {strings: $a = /[1-9a-zA-z]{34}(?!OIl)/ condition: $a}'
        })
        for task in bit_tasks:
            scanner = mac_yarascan.MapYaraScanner(task=task, rules=addr_rule)
            for hit, address in scanner.scan():
                content = scanner.address_space.zread(address, 34)
                if pyenc.is_valid_bitcoin_address(
                        content) and content not in bit_addrs:
                    bit_addrs.append(content)

        # scan for bitcoin keys with yara, 52 char compressed base58, starts with L or K, https://en.bitcoin.it/wiki/Private_key
        addr_key = {}
        key_rule = yara.compile(sources={
            'n':
            'rule r1 {strings: $a = /(L|K)[0-9A-Za-z]{51}/ condition: $a}'
        })
        for task in bit_tasks:
            scanner = mac_yarascan.MapYaraScanner(task=task, rules=key_rule)
            for hit, address in scanner.scan():
                content = scanner.address_space.zread(address, 52)
                if pyenc.is_valid_wif(content):
                    secret_exp = pyenc.wif_to_secret_exponent(content)
                    key = pykey.Key(secret_exponent=secret_exp,
                                    is_compressed=True)
                    if key.address() not in addr_key.keys():
                        addr_key[key.address()] = content
                        yield (content, key.address())

        # addresses with no known keys
        for bit_addr in bit_addrs:
            if bit_addr not in addr_key.keys():
                yield ("UNKNOWN", bit_addr)
Beispiel #2
0
 def is_valid(self, wif):
     if is_valid_wif(wif):
         self.logger.info("Valid WIF: " + wif)
         return True
     else:
         self.logger.debug("Invalid WIF: " + wif)
         return False
Beispiel #3
0
 def do_test(as_secret_exponent, as_wif, is_compressed):
     self.assertEqual(
         as_wif,
         encoding.secret_exponent_to_wif(as_secret_exponent,
                                         compressed=is_compressed))
     se, comp = encoding.wif_to_tuple_of_secret_exponent_compressed(
         as_wif)
     self.assertEqual(se, as_secret_exponent)
     self.assertEqual(comp, is_compressed)
     self.assertTrue(encoding.is_valid_wif(as_wif))
Beispiel #4
0
def processQRCode(code):
    print "The QR Code says " + code
    if is_valid_bitcoin_address(code):
        print "this is a bitcoin address"
        giveBTC(code)
    elif is_valid_wif(code):
        print "this is a private key"
        takeBTC(code)
    else:
        print "this is not a bitcoin address or private key"
Beispiel #5
0
    def calculate(self):
        all_tasks = pstasks.mac_tasks(self._config).allprocs()
        bit_tasks = []

        try:
            if self._config.PID:
                # find tasks given PIDs
                pidlist = [int(p) for p in self._config.PID.split(',')]
                bit_tasks = [t for t in all_tasks if t.p_pid in pidlist]
            else:
                # find multibit process
                name_re = re.compile("JavaApplicationS", re.I)
                bit_tasks = [t for t in all_tasks if name_re.search(str(t.p_comm))]
        except:
            pass

        if len(bit_tasks) == 0:
            yield (None, None)


        # scan for bitcoin addresses with yara, 34 chars, https://en.bitcoin.it/wiki/Address
        # Most Bitcoin addresses are 34 characters. They consist of random digits and uppercase 
        # and lowercase letters, with the exception that the uppercase letter "O", uppercase 
        # letter "I", lowercase letter "l", and the number "0" are never used to prevent visual ambiguity.
        bit_addrs = []
        addr_rule = yara.compile(sources = {'n' : 'rule r1 {strings: $a = /[1-9a-zA-z]{34}(?!OIl)/ condition: $a}'})
        for task in bit_tasks:
            scanner = mac_yarascan.MapYaraScanner(task = task, rules = addr_rule)
            for hit, address in scanner.scan():
                content = scanner.address_space.zread(address, 34)
                if pyenc.is_valid_bitcoin_address(content) and content not in bit_addrs:
                    bit_addrs.append(content)

        # scan for bitcoin keys with yara, 52 char compressed base58, starts with L or K, https://en.bitcoin.it/wiki/Private_key
        addr_key = {}
        key_rule = yara.compile(sources = {'n' : 'rule r1 {strings: $a = /(L|K)[0-9A-Za-z]{51}/ condition: $a}'})
        for task in bit_tasks:
            scanner = mac_yarascan.MapYaraScanner(task = task, rules = key_rule)
            for hit, address in scanner.scan():
                content = scanner.address_space.zread(address, 52)
                if pyenc.is_valid_wif(content):
                    secret_exp = pyenc.wif_to_secret_exponent(content)
                    key = pykey.Key(secret_exponent = secret_exp,is_compressed=True)
                    if key.address() not in addr_key.keys():
                        addr_key[key.address()] = content
                        yield(content, key.address())

        # addresses with no known keys
        for bit_addr in bit_addrs:
            if bit_addr not in addr_key.keys():
                yield ("UNKNOWN", bit_addr)
Beispiel #6
0
def processQRCode(code):
	print "The QR Code says " + code
	if is_valid_bitcoin_address(code):
		print "this is a bitcoin address"
		giveBTC(code)
		print "main thread: telling camera to start"
		to_cam.put('start') # reset for the next person
	elif is_valid_wif(code):
		print "this is a private key"
		takeBTC(code)
		print "main thread: telling camera to start"
		to_cam.put('start') # reset for the next person
	else:
		print "this is not a bitcoin address or private key"
Beispiel #7
0
    def createTx(self):

        # address = self.fromaddress.text()
        # destination = self.sendto.text()

        address = "mti8znMQPkP9LnPcce7i3LQRuSGZ38PVPV"
        destination = "ms4cSWpPGb6tBzbBXNuBwsarg1SNYvkjxg"

        #あらかじめ送信元アドレスに対応する秘密鍵を入力しておく
        wif = "cNJm4inEA9xreDHntBB9gAFj8V6aSn9sqdVgDdJJGrN9Ys8b8vzD"
        sndtx = BlockchainInfoProvider('blockr.io')

        print("before")
        assert is_valid_wif(wif)
        print("after")

        spendables = spendables_for_address(address, "BTC")
        tx = create_signed_tx(spendables, payables=[destination], wifs=[wif])
        sndtx.broadcast_tx(tx)
        self.transaction.setText(tx.as_hex())
            HEADER_DICT[header] = header
        myWriter.writerow(HEADER_DICT)

        for key_cnt in range(NUM_KEYS_TO_GENERATE):
            wallet = generate_random_wallet()
            public_address = wallet.bitcoin_address()
            wif = wallet.wif()
            wallet_dict = {
                'born_at': datetime.now(),
                'wif': wif,
                'public_bitcoin_address': public_address,
            }
            myWriter.writerow(wallet_dict)

            # weak safety checks
            assert is_valid_wif(wif)
            assert wif not in all_wifs
            assert public_address not in all_public_addresses

            # add wallet to set
            all_wifs.add(wif)
            all_public_addresses.add(public_address)

            # print out progress
            if key_cnt % 500 == 0:
                print key_cnt, datetime.now()

    END_TIME = datetime.now()
    print 'Finished generating %s private keys at %s (%s run time)' % (
        key_cnt + 1, END_TIME, END_TIME - START_TIME)
 def do_test(as_secret_exponent, as_wif, is_compressed):
     self.assertEqual(as_wif, encoding.secret_exponent_to_wif(as_secret_exponent, compressed=is_compressed))
     se, comp = encoding.wif_to_tuple_of_secret_exponent_compressed(as_wif)
     self.assertEqual(se, as_secret_exponent)
     self.assertEqual(comp, is_compressed)
     self.assertTrue(encoding.is_valid_wif(as_wif))
        for header in HEADERS:
            HEADER_DICT[header]=header
        myWriter.writerow(HEADER_DICT)

        for key_cnt in range(NUM_KEYS_TO_GENERATE):
            wallet = generate_random_wallet()
            public_address = wallet.bitcoin_address()
            wif = wallet.wif()
            wallet_dict = {
                'born_at': datetime.now(),
                'wif': wif,
                'public_bitcoin_address': public_address,
                }
            myWriter.writerow(wallet_dict)

            # weak safety checks
            assert is_valid_wif(wif)
            assert wif not in all_wifs
            assert public_address not in all_public_addresses

            # add wallet to set
            all_wifs.add(wif)
            all_public_addresses.add(public_address)

            # print out progress
            if key_cnt % 500 == 0:
                print key_cnt, datetime.now()

    END_TIME = datetime.now()
    print 'Finished generating %s private keys at %s (%s run time)' % (key_cnt+1, END_TIME, END_TIME-START_TIME)