#!/usr/bin/python3importsysimportnumpyasnpfromPILimportImageimporttorchimporttorch.nnasnnfromtorchvision.modelsimportresnet34importbase64importiomodel=resnet34()model.fc=nn.Linear(model.fc.in_features,2)model.load_state_dict(torch.load('/model.pth',map_location='cpu'))model.eval()ori=np.array(Image.open("/Cain's_dog.png"))base64_string=input("Could u help me find my dog?Please give me the base64 of the dog image:\n")image_bytes=base64.b64decode(base64_string)buffered=io.BytesIO(image_bytes)img=Image.open(buffered)inp=np.array(img)different_pixels_count=(ori!=inp).sum()ifdifferent_pixels_count>100:print('Not My Dog!!!')exit(0)outputs=torch.tensor(inp.transpose(2,0,1)/255.0,dtype=torch.float32).unsqueeze(0)pred=torch.softmax(model(outputs),dim=1)ifpred[0][0]<0.9:print("This dog doesn't meow~ , he's not my dog")exit(0)print("Yes, my dog is about to become a cat girl! miao~")print("flag{}")
# -*- coding: utf-8 -*-# @Author : 1cePeakimporttorchimporttorch.nnasnnimportnumpyasnpfromPILimportImagefromtorchvision.modelsimportresnet34fromtorchvision.utilsimportsave_imagedefperturb(p,img):# Elements of p should be in range [0,1]img_size=img.size(1)# C x _H_ x W, assume H == Wp_img=img.clone()xy=(p[0:2].copy()*img_size).astype(int)xy=np.clip(xy,0,img_size-1)rgb=p[2:5].copy()rgb=np.clip(rgb,0,1)p_img[:,xy[0],xy[1]]=torch.from_numpy(rgb)returnp_imgmodel=resnet34()model.fc=nn.Linear(model.fc.in_features,2)model.load_state_dict(torch.load('./model.pth',map_location='cpu'))model.eval()ori=np.array(Image.open("./Cain's_dog.png"))test_img=torch.tensor(ori.transpose(2,0,1)/255.0,dtype=torch.float32).unsqueeze(0)attack_img1=perturb(np.array([3.58966099e-01,6.56811724e-01,5.87733625e-01,1.13867609e-04,2.97430753e-05]),test_img[0])attack_img2=perturb(np.array([0.34090759,0.79827122,1.,0.,0.21769902]),attack_img1)attack_img3=perturb(np.array([0.59172661,0.63182162,0.06213244,0.02224004,0.]),attack_img2)attack_img4=perturb(np.array([0.33929994,0.40123714,0.60364848,0.49595161,0.]),attack_img3)attack_img5=perturb(np.array([0.26169169,0.35602058,0.,0.47890641,0.42390094]),attack_img4)attack_img6=perturb(np.array([0.29596823,0.79582006,0.,0.13034493,0.10614204]),attack_img5)attack_img7=perturb(np.array([0.72041558,0.4443911,0.79512668,0.82490795,0.35141815]),attack_img6)pred=torch.softmax(model(attack_img7.reshape(1,3,224,224)),dim=1)print(pred)save_image(attack_img7,'./res.png')
#!/usr/bin/python3importsysimportnumpyasnpfromPILimportImageimporttorchimporttorch.nnasnnfromtorchvision.modelsimportresnet34importbase64importiomodel=resnet34()model.fc=nn.Linear(model.fc.in_features,2)model.load_state_dict(torch.load('./model.pth',map_location='cpu'))model.eval()ori=np.array(Image.open("./Cain's_dog.png"))# base64_string = input("Could u help me find my dog?Please give me the base64 of the dog image:\n")# image_bytes = base64.b64decode(base64_string)# buffered = io.BytesIO(image_bytes)# img = Image.open(buffered)# inp = np.array(img)inp=np.array(Image.open("./res.png"))different_pixels_count=(ori!=inp).sum()ifdifferent_pixels_count>100:print('Not My Dog!!!')exit(0)outputs=torch.tensor(inp.transpose(2,0,1)/255.0,dtype=torch.float32).unsqueeze(0)pred=torch.softmax(model(outputs),dim=1)ifpred[0][0]<0.9:print("This dog doesn't meow~ , he's not my dog")exit(0)print("Yes, my dog is about to become a cat girl! miao~")print("flag{}")
X:
Frame 87: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface \\.\USBPcap2, id 0
USB URB
Bluetooth
Bluetooth HCI USB Transport
Bluetooth HCI ACL Packet
Bluetooth L2CAP Protocol
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
Handle: 0x0007 (Unknown)
Value: 0080ff7f0080ff7f0000000000080000
Y:
Frame 91: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface \\.\USBPcap2, id 0
USB URB
Bluetooth
Bluetooth HCI USB Transport
Bluetooth HCI ACL Packet
Bluetooth L2CAP Protocol
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
Handle: 0x0007 (Unknown)
Value: 0080ff7f0080ff7f0000000000100000
A:
Frame 95: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface \\.\USBPcap2, id 0
USB URB
Bluetooth
Bluetooth HCI USB Transport
Bluetooth HCI ACL Packet
Bluetooth L2CAP Protocol
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
Handle: 0x0007 (Unknown)
Value: 0080ff7f0080ff7f0000000000010000
B:
Frame 99: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface \\.\USBPcap2, id 0
USB URB
Bluetooth
Bluetooth HCI USB Transport
Bluetooth HCI ACL Packet
Bluetooth L2CAP Protocol
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
Handle: 0x0007 (Unknown)
Value: 0080ff7f0080ff7f0000000000020000
上:
Frame 115: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface \\.\USBPcap2, id 0
USB URB
Bluetooth
Bluetooth HCI USB Transport
Bluetooth HCI ACL Packet
Bluetooth L2CAP Protocol
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
Handle: 0x0007 (Unknown)
Value: 0080ff7f0080ff7f0000000001000000
下:
Frame 131: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface \\.\USBPcap2, id 0
USB URB
Bluetooth
Bluetooth HCI USB Transport
Bluetooth HCI ACL Packet
Bluetooth L2CAP Protocol
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
Handle: 0x0007 (Unknown)
Value: 0080ff7f0080ff7f0000000005000000
左:
Frame 135: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface \\.\USBPcap2, id 0
USB URB
Bluetooth
Bluetooth HCI USB Transport
Bluetooth HCI ACL Packet
Bluetooth L2CAP Protocol
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
Handle: 0x0007 (Unknown)
Value: 0080ff7f0080ff7f0000000007000000
右:
Frame 139: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface \\.\USBPcap2, id 0
USB URB
Bluetooth
Bluetooth HCI USB Transport
Bluetooth HCI ACL Packet
Bluetooth L2CAP Protocol
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
Handle: 0x0007 (Unknown)
Value: 0080ff7f0080ff7f0000000003000000
rb:
Frame 31: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface \\.\USBPcap2, id 0
USB URB
Bluetooth
Bluetooth HCI USB Transport
Bluetooth HCI ACL Packet
Bluetooth L2CAP Protocol
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
Handle: 0x0007 (Unknown)
Value: 0080ff7f0080ff7f0000000000800000
lb:
Frame 35: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface \\.\USBPcap2, id 0
USB URB
Bluetooth
Bluetooth HCI USB Transport
Bluetooth HCI ACL Packet
Bluetooth L2CAP Protocol
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
Handle: 0x0007 (Unknown)
Value: 0080ff7f0080ff7f0000000000400000
左摇杆向右:前4个字节变化,猜测表示坐标
Frame 73: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface \\.\USBPcap2, id 0
USB URB
Bluetooth
Bluetooth HCI USB Transport
Bluetooth HCI ACL Packet
Bluetooth L2CAP Protocol
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
Handle: 0x0007 (Unknown)
Value: 49 6a f4 82 0080ff7f0000000000000000
lt与rt存在多组数据,猜测与力度有关(油门)