Example #1
0
  def __init__(self, num_players=5,
               rules=table_rules.DEFAULT_TABLE_RULES):
    """Constructor.

    Args:
      num_players: int, total number of players at the table. Excludes Dealer.
      rules: table_rules.TableRules, table rules.
    """
    # Rules and strategy
    self.table_rules = rules

    # Sanity check number of players.
    if 1 < num_players > self.table_rules.max_num_seats:
      raise GameException(
          'Must be between 1-%d players total.' % self.table_rules.max_num_seats)
    self.num_players = num_players

    # TODO(self): Support multiple play strategies.
    self.play_strategy = play_strategy.PlayStrategy(self.table_rules)

    # Initialize people.
    self.dealer = person.Dealer(self.table_rules)
    self.player = person.Player(self.table_rules, self.play_strategy)

    # Initializing game parameters.
    self.game_stats = stats.GameStats()
    self.shoe = shoe.Shoe(self.table_rules.num_decks)
Example #2
0
    def __init__(self, players, deck_amount, pen_amount):
        """
        - Pass how many decks will be in the shoe.
        - Ensure dealer knows how many players are playing via 'confirm_player'
        """
        self.decks = sh.Shoe(deck_amount)
        self.decks.shuffle()

        self.dealer = dl.Dealer(self.decks)
        self.set_deck_threshold()

        self.players = players
        self.confirm_players(self.players)

        # Holds cards cleared at the end of each round
        self.trash_pile = []

        # Average shoe penetration in Blackjack is usually 25% (0.25)
        self.pen = len(self.decks) * (pen_amount / 100)
    def test_reset(self):
        # Test vars
        decks = 4
        num_burn_cards = 2

        self.shoe = shoe.Shoe(decks)

        # Initial state.
        self.assertEqual(self.shoe.GetNumCardsPlayed(), decks)

        # Play round.
        self.shoe.BurnCards(num_burn_cards)

        # Final state.
        self.assertEqual(self.shoe.GetNumCardsPlayed(), decks + num_burn_cards)

        # Reset state should equal initial state.
        self.shoe.Reset()
        self.assertEqual(self.shoe.GetNumCardsPlayed(), decks)
Example #4
0
	gdb.execute("r " + args)

	T6 = gdb.parse_and_eval("*(unsigned int*)$esp")
	T7 = gdb.parse_and_eval("*(unsigned int*)($esp + 4)")

	print("T6 = {} T7 = {}".format(T6,T7))
	return (T6, T7)

def crack_keys(T6, T7):
	keypart1 = T6 ^ 0x31333337
	keypart2 = (T7 & 0x000000FF) | (((T7 & 0x00FF0000) >> 16) << 8) | (((T7 & 0xFF000000) >> 24) << 16) | (((T7 & 0x0000FF00) >> 8) << 24) 
	return (keypart1, keypart2)

## Talk to the server and get what username it wants
## then send it back the cracked key
s = shoe.Shoe('localhost', 12123)
resp = s.read_until("\r\n") # Welcome msg
for i in range(0,10):
	resp = s.read_until("\n").decode('utf-8') # Username msg
	print(resp)
	#username = resp.lstrip("give me the password for ").rstrip()
	username = resp[-23:].rstrip()
	print(username)
	t6, t7 = get_t6t7(username)
	keypart1, keypart2 = crack_keys(t6, t7)

	ans = "{} {}\n".format(str(int(keypart1)), str(int(keypart2)))
	s.write(ans)
	resp = s.read_until("\n").decode('utf-8') # The smiley
	print(resp)
Example #5
0
def main():
    exchange = connect()
    write_to_exchange(exchange, {"type": "hello", "team": team_name.upper()})
    hello_from_exchange = read_from_exchange(exchange)

    # A common mistake people make is to call write_to_exchange() > 1
    # time for every read_from_exchange() response.
    # Since many write messages generate marketdata, this will cause an
    # exponential explosion in pending messages. Please, don't do that!

    cash = [0]
    positions = {
        'BOND': 0,
        'BABZ': 0,
        'BABA': 0,
        'AAPL': 0,
        'MSFT': 0,
        'GOOG': 0,
        'XLK': 0
    }
    book = {}
    all_trades = {}
    order_obj = Order()

    # print("The exchange replied:", hello_from_exchange, file=sys.stderr)
    # print(type(hello_from_exchange))
    # print(hello_from_exchange.keys())

    for item in hello_from_exchange["symbols"]:
        positions[item['symbol']] = item['position']
    # print(positions)

    bond_obj = bond.Bond()

    # bond_obj.hello()

    trades = bond_obj.trade(order_obj, positions, all_trades)
    for trade in trades:
        all_trades[trade['order_id']] = trade
        write_to_exchange(exchange, trade)

    baaz_obj = baaz.Baaz()
    trades = baaz_obj.trade(book, order_obj, positions, all_trades)
    for trade in trades:
        all_trades[trade['order_id']] = trade
        write_to_exchange(exchange, trade)

    trades = baaz_obj.baba2baaz(book, order_obj, positions)
    for trade in trades:
        all_trades[trade['order_id']] = trade
        write_to_exchange(exchange, trade)

    trades = baaz_obj.baaz2baba(book, order_obj, positions)
    for trade in trades:
        all_trades[trade['order_id']] = trade
        write_to_exchange(exchange, trade)

    shoe_obj = shoe.Shoe()
    trades = shoe_obj.trade(book, order_obj, positions, all_trades)
    for trade in trades:
        all_trades[trade['order_id']] = trade
        write_to_exchange(exchange, trade)

    counter = 0

    reply = read_from_exchange(exchange)
    if (reply['type'] == 'reject'):
        return

    book_ctr = 0
    trade_ctr = 0
    OK_ctr = 0
    while (1):
        # book_ctr += 1
        if (book_ctr % 100 == 0):
            if 'SHOE' in book and 'BAAZ' in book and 'NIKE' in book and 'ADID' in book and 'FYUE' in book and 'BOND' in book and \
              len(book['BOND']['sell']) > 0 and len(book['BOND']['buy']) > 0 and \
              len(book['SHOE']['sell']) > 0 and len(book['SHOE']['buy']) > 0 and \
              len(book['BAAZ']['sell']) > 0 and len(book['BAAZ']['buy']) > 0 and \
              len(book['NIKE']['sell']) > 0 and len(book['NIKE']['buy']) > 0 and \
              len(book['ADID']['sell']) > 0 and len(book['ADID']['buy']) > 0 and \
              len(book['FYUE']['sell']) > 0 and len(book['FYUE']['buy']) > 0:
                shoe_sell = 10 * book['SHOE']['sell'][0][0]
                other_sell = 3 * book['BOND']['sell'][0][0] + 2 * book['NIKE']['sell'][0][0] + \
                       3 * book['ADID']['sell'][0][0] + 2 * book['FYUE']['sell'][0][0]
                shoe_buy = 10 * book['SHOE']['buy'][0][0]
                other_buy = 3 * book['BOND']['buy'][0][0] + 2 * book['NIKE']['buy'][0][0] + \
                      3 * book['ADID']['buy'][0][0] + 2 * book['FYUE']['buy'][0][0]
                # trade_ctr += 1
                # if shoe_sell < other_buy or other_sell < shoe_buy:
                # 	OK_ctr += 1

                # print("SHOE: ", 'sell:', 10 * book['SHOE']['sell'][0][0], ' buy:', 10 * book['SHOE']['buy'][0][0], ' ', end="")
                # print("OTHERS: ", 'sell:', 3 * book['BOND']['sell'][0][0] + 2 * book['NIKE']['sell'][0][0] +\
                # 			3 * book['ADID']['sell'][0][0] + 2 * book['FYUE']['sell'][0][0],
                # 			' buy:', 3 * book['BOND']['buy'][0][0] + 2 * book['NIKE']['buy'][0][0] +\
                # 			3 * book['ADID']['buy'][0][0] + 2 * book['FYUE']['buy'][0][0])
                # print("OK percent: ", float(OK_ctr) / trade_ctr, "OK: ", OK_ctr)
            book_ctr = 0

        reply = read_from_exchange(exchange)

        if (reply['type'] == 'book'):
            counter += 1
            if counter % 100 == 0:
                print("im running ", counter)
                counter = 0
            # print(1)
            # print("book: ", reply)
            book[reply['symbol']] = {
                'buy': reply['buy'],
                'sell': reply['sell']
            }
            trades = baaz_obj.baba2baaz(book, order_obj, positions)
            for trade in trades:
                all_trades[trade['order_id']] = trade
                write_to_exchange(exchange, trade)

            trades = baaz_obj.baaz2baba(book, order_obj, positions)
            for trade in trades:
                all_trades[trade['order_id']] = trade
                write_to_exchange(exchange, trade)

            trades = baaz_obj.trade(book, order_obj, positions, all_trades)
            for trade in trades:
                all_trades[trade['order_id']] = trade
                write_to_exchange(exchange, trade)

            trades = shoe_obj.shoe2other(book, order_obj, positions)
            for trade in trades:
                all_trades[trade['order_id']] = trade
                write_to_exchange(exchange, trade)

            trades = shoe_obj.other2shoe(book, order_obj, positions)
            for trade in trades:
                all_trades[trade['order_id']] = trade
                write_to_exchange(exchange, trade)

            trades = shoe_obj.trade(book, order_obj, positions, all_trades)
            for trade in trades:
                all_trades[trade['order_id']] = trade
                write_to_exchange(exchange, trade)

        elif (reply['type'] == 'fill'):
            # print(2)
            if (reply['dir'] == 'buy'):
                positions[reply['symbol']] += reply['size']
                cash -= reply['size'] * reply['price']
                all_trades[reply['order_id']] -= reply['size']
                if (all_trades[reply['order_id']] == 0):
                    all_trades.pop(reply['order_id'])

            elif (reply['dir'] == 'sell'):
                # print(3)
                positions[reply['symbol']] -= reply['size']
                cash += reply['size'] * reply['price']
                all_trades[reply['order_id']] -= reply['size']
                if (all_trades[reply['order_id']] == 0):
                    all_trades.pop(reply['order_id'])
            # print("log, fill-reply received: ", reply)

        elif (reply['type'] == 'out'):
            # print(4)
            trades = bond_obj.trade(order_obj, positions, all_trades)
            for trade in trades:
                all_trades[trade['order_id']] = trade
                write_to_exchange(exchange, trade)

        elif (reply['type'] == 'ack'):
            # print("ack", reply)
            pass
        elif (reply['type'] == 'reject'):
            # print("reject", reply)
            pass
Example #6
0
#!/usr/bin/python
import shoe

s = shoe.Shoe('localhost', 30002)
for i in range(0, 9999):
    cmd = "UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ {}".format(i)
    s.write(cmd + "\n")
    r = s.read_until_end(.001)
    if "Wrong!" not in r and len(r) > 10:
        print(r)
Example #7
0
#!/usr/bin/python
import shoe
import struct
import sys

print("-------------------------------")
print(
    "You are running the test for `shoe`, a remote exploitation library for CTFs"
)
print("View this file test_shoe.py, to understand how to use shoe")

## This run shouldn't pwn.
print("[*] Not pwning...")
s = shoe.Shoe('pwnable.kr', 9000)

resp = s.read_for(2)  # Should return nothing
print(resp)

s.write("hi\n")

resp = s.read_until("me :")  # Should return "overflow me :"
print(resp)

resp = s.read_until_end()  # Should return "\nNah..\n"
print(resp)

s.close()

## This run should pwn.
print("[*] Pwning...")
s = shoe.Shoe('pwnable.kr', 9000)
 def setUp(self):
     self.shoe = shoe.Shoe(num_decks=4)