Module: PWN::Plugins::MSR206
- Defined in:
- lib/pwn/plugins/msr206.rb
Overview
This plugin is used for interacting with a three track MSR206 Magnetic Stripe Reader / Writer
Class Method Summary collapse
-
.authors ⇒ Object
- Author(s)
-
0day Inc.
-
.backup_card(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.backup_card( msr206_obj: ‘required - msr206_obj returned from #connect method’ ).
-
.connect(opts = {}) ⇒ Object
- Supported Method Parameters
-
msr206_obj = PWN::Plugins::MSR206.connect( block_dev: ‘optional - serial block device path (defaults to /dev/ttyUSB0)’, baud: ‘optional - (defaults to 9600)’, data_bits: ‘optional - (defaults to 8)’, stop_bits: ‘optional - (defaults to 1)’, parity: ‘optional - :even|:mark|:odd|:space|:none (defaults to :none),’ flow_control: ‘optional - :none|:hard|:soft (defaults to :soft)’ ).
-
.copy_card(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.copy_card( msr206_obj: ‘required - msr206_obj returned from #connect method’ ).
-
.disconnect(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.disconnect( msr206_obj: ‘required - msr206_obj returned from #connect method’ ).
-
.exec(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.exec( msr206_obj: ‘required - msr206_obj returned from #connect method’ cmd: ‘required - cmd returned from #list_cmds method’, params: ‘optional - parameters for specific command returned from #list_params method’ ).
-
.get_config(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.get_config( msr206_obj: ‘required - msr206_obj returned from #connect method’ ).
-
.help ⇒ Object
Display Usage for this Module.
-
.list_cmds ⇒ Object
- Supported Method Parameters
-
cmds = PWN::Plugins::MSR206.list_cmds.
-
.load_card_from_file(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.load_card_from_file( msr206_obj: ‘required - msr206_obj returned from #connect method’ ).
-
.read_card(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.read_card( msr206_obj: ‘required - msr206_obj returned from #connect method’ ).
-
.write_card(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.write_card( msr206_obj: ‘required - msr206_obj returned from #connect method’, encoding: ‘required - :iso || :alt_iso || :raw’, track_data: ‘requred - track data to write (see #backup_card for structure)’ ).
Class Method Details
.authors ⇒ Object
- Author(s)
-
0day Inc. <[email protected]>
1157 1158 1159 1160 1161 |
# File 'lib/pwn/plugins/msr206.rb', line 1157 public_class_method def self. "AUTHOR(S): 0day Inc. <[email protected]> " end |
.backup_card(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.backup_card(
msr206_obj: 'required - msr206_obj returned from #connect method'
)
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 |
# File 'lib/pwn/plugins/msr206.rb', line 884 public_class_method def self.backup_card(opts = {}) msr206_obj = opts[:msr206_obj] type = opts[:type].to_s.scrub.strip.chomp.to_sym # Read Card to Backup track_data = read_card( msr206_obj: msr206_obj ) file = '' backup_msg = '' loop do if backup_msg.empty? exec_resp = exec( msr206_obj: msr206_obj, cmd: :green_flash ) end print 'Enter File Name to Save Backup: ' file = gets.scrub.chomp.strip file_dir = File.dirname(file) break if Dir.exist?(file_dir) backup_msg = "\n****** ERROR: Directory #{file_dir} for #{file} does not exist ******" puts backup_msg exec_resp = exec( msr206_obj: msr206_obj, cmd: :green_off ) exec_resp = exec( msr206_obj: msr206_obj, cmd: :yellow_flash ) end File.write(file, "#{JSON.pretty_generate(track_data)}\n") exec_resp = exec( msr206_obj: msr206_obj, cmd: :yellow_off ) puts 'complete.' track_data rescue StandardError => e raise e end |
.connect(opts = {}) ⇒ Object
- Supported Method Parameters
-
msr206_obj = PWN::Plugins::MSR206.connect(
block_dev: 'optional - serial block device path (defaults to /dev/ttyUSB0)', baud: 'optional - (defaults to 9600)', data_bits: 'optional - (defaults to 8)', stop_bits: 'optional - (defaults to 1)', parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none),' flow_control: 'optional - :none|:hard|:soft (defaults to :soft)'
)
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pwn/plugins/msr206.rb', line 18 public_class_method def self.connect(opts = {}) # Default Baud Rate for this Device is 19200 opts[:block_dev] = '/dev/ttyUSB0' unless opts[:block_dev] opts[:baud] = 9_600 unless opts[:baud] opts[:data_bits] = 8 unless opts[:data_bits] opts[:stop_bits] = 1 unless opts[:stop_bits] opts[:parity] = :none unless opts[:parity] opts[:flow_control] = :soft unless opts[:flow_control] msr206_obj = PWN::Plugins::Serial.connect(opts) rescue StandardError => e disconnect(msr206_obj: msr206_obj) unless msr206_obj.nil? raise e end |
.copy_card(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.copy_card(
msr206_obj: 'required - msr206_obj returned from #connect method'
)
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 |
# File 'lib/pwn/plugins/msr206.rb', line 1013 public_class_method def self.copy_card(opts = {}) msr206_obj = opts[:msr206_obj] # Read Card to Backup track_data = backup_card( msr206_obj: msr206_obj ) encoding = track_data.first[:encoding] if track_data.length == 3 write_card( msr206_obj: msr206_obj, encoding: encoding, track_data: track_data ) rescue StandardError => e raise e end |
.disconnect(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.disconnect(
msr206_obj: 'required - msr206_obj returned from #connect method'
)
1147 1148 1149 1150 1151 1152 1153 |
# File 'lib/pwn/plugins/msr206.rb', line 1147 public_class_method def self.disconnect(opts = {}) PWN::Plugins::Serial.disconnect( serial_obj: opts[:msr206_obj] ) rescue StandardError => e raise e end |
.exec(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.exec(
msr206_obj: 'required - msr206_obj returned from #connect method' cmd: 'required - cmd returned from #list_cmds method', params: 'optional - parameters for specific command returned from #list_params method'
)
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
# File 'lib/pwn/plugins/msr206.rb', line 431 public_class_method def self.exec(opts = {}) msr206_obj = opts[:msr206_obj] cmd = opts[:cmd].to_s.scrub.strip.chomp params = opts[:params] raise 'ERROR: params argument must be a byte array (e.g. [0x41]).' if params && !params.instance_of?(Array) params_bytes = [] case cmd.to_sym when :proto_usi0 cmd_bytes = [0x55, 0x53, 0x49, 0x30] when :proto_usi1 cmd_bytes = [0x55, 0x53, 0x49, 0x31] when :resume_transmission_to_host cmd_bytes = [0x11] when :pause_transmission_to_host cmd_bytes = [0x13] when :abort_command cmd_bytes = [0x1B] when :configuration_request cmd_bytes = [0x23] when :reproduce_last_command cmd_bytes = [0x25] when :card_edge_detect cmd_bytes = [0x26] when :green_flash cmd_bytes = [0x28] when :red_flash cmd_bytes = [0x29] when :version_report cmd_bytes = [0x39] when :set_write_density cmd_bytes = [0x3B] when :set_temp_write_current cmd_bytes = [0x3C] when :view_temp_write_current cmd_bytes = [0x3E] when :write_verify cmd_bytes = [0x3F] when :arm_to_write_with_raw cmd_bytes = [0x40] when :load_iso_std_data_for_writing_track1 cmd_bytes = [0x41] when :load_iso_std_data_for_writing_track2 cmd_bytes = [0x42] when :load_iso_std_data_for_writing_track3 cmd_bytes = [0x43] when :load_custom_data_for_writing_track1 cmd_bytes = [0x45] when :load_custom_data_for_writing_track2 cmd_bytes = [0x46] when :load_custom_data_for_writing_track3 cmd_bytes = [0x47] when :tx_error_data cmd_bytes = [0x49] when :yellow_on cmd_bytes = [0x4B] when :green_on cmd_bytes = [0x4C] when :red_on cmd_bytes = [0x4D] when :set_write_density_210_bpi_tracks2 cmd_bytes = [0x4E] when :set_write_density_210_bpi_tracks13 cmd_bytes = [0x4F] when :arm_to_read cmd_bytes = [0x50] when :tx_iso_std_data_track1 cmd_bytes = [0x51] when :tx_iso_std_data_track2 cmd_bytes = [0x52] when :tx_iso_std_data_track3 cmd_bytes = [0x53] when :tx_custom_data_forward_track1 cmd_bytes = [0x55] when :tx_custom_data_forward_track2 cmd_bytes = [0x56] when :tx_custom_data_forward_track3 cmd_bytes = [0x57] when :tx_passbook_data cmd_bytes = [0x58] when :arm_to_write_no_raw cmd_bytes = [0x5A] when :set_default_write_current cmd_bytes = [0x5B] when :view_default_write_current cmd_bytes = [0x5D] when :alt_load_iso_std_data_for_writing_track1 cmd_bytes = [0x61] when :alt_load_iso_std_data_for_writing_track2 cmd_bytes = [0x62] when :alt_load_iso_std_data_for_writing_track3 cmd_bytes = [0x63] when :load_passbook_data_for_writing cmd_bytes = [0x6A] when :yellow_off cmd_bytes = [0x6B] when :green_off cmd_bytes = [0x6C] when :red_off cmd_bytes = [0x6D] when :set_write_density_75_bpi_tracks2 cmd_bytes = [0x6E] when :set_write_density_75_bpi_tracks13 cmd_bytes = [0x6F] when :arm_to_read_w_speed_prompts cmd_bytes = [0x70] when :alt_tx_iso_std_data_track1 cmd_bytes = [0x71] when :alt_tx_iso_std_data_track2 cmd_bytes = [0x72] when :alt_tx_iso_std_data_track3 cmd_bytes = [0x73] when :alt_tx_passbook_data cmd_bytes = [0x78] when :arm_to_write_with_raw_speed_prompts cmd_bytes = [0x7A] when :yellow_flash cmd_bytes = [0x7C] when :simulate_power_cycle_warm_reset cmd_bytes = [0x7F] else raise "Unsupported Command: #{cmd}. Supported commands are:\n#{list_cmds}\n\n\n" end # If parameters to a command are set, append them. cmd_bytes += params if params # Execute the command. PWN::Plugins::Serial.request( serial_obj: msr206_obj, payload: cmd_bytes ) # Parse commands response(s). # Return an array of hashes. parse_responses( msr206_obj: msr206_obj, cmd: cmd.to_sym, cmd_bytes: cmd_bytes ) rescue StandardError => e raise e ensure # Flush Responses for Next Request PWN::Plugins::Serial.flush_session_data end |
.get_config(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.get_config(
msr206_obj: 'required - msr206_obj returned from #connect method'
)
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 |
# File 'lib/pwn/plugins/msr206.rb', line 1091 public_class_method def self.get_config(opts = {}) msr206_obj = opts[:msr206_obj] # -------------------------------------------------- # Bit|Bit = 0 |Bit = 1 # -------------------------------------------------- # 0 |Track 1 Read not present |Track 1 Read present # 1 |Track 2 Read not present |Track 2 Read present # 2 |Track 3 Read not present |Track 3 Read present # 3 |not used – should be 0 |not used # 4 |Track 3 Write not present|Track 3 Write present # 5 |Track 2 Write not present|Track 2 Write present # 6 |Track 1 Write not present|Track 1 Write present # 7 |parity bit** |parity bit** exec_resp = PWN::Plugins::MSR206.exec( msr206_obj: msr206_obj, cmd: :configuration_request ) config_arr = exec_resp[:binary].first.reverse.chars config_hash = {} config_arr.each_with_index do |bit_str, i| bit = bit_str.to_i config_hash[:track1_read] = false if bit.zero? && i.zero? config_hash[:track1_read] = true if bit == 1 && i.zero? config_hash[:track2_read] = false if bit.zero? && i == 1 config_hash[:track2_read] = true if bit == 1 && i == 1 config_hash[:track3_read] = false if bit.zero? && i == 2 config_hash[:track3_read] = true if bit == 1 && i == 2 config_hash[:not_used] if i == 3 config_hash[:track1_write] = false if bit.zero? && i == 4 config_hash[:track1_write] = true if bit == 1 && i == 4 config_hash[:track2_write] = false if bit.zero? && i == 5 config_hash[:track2_write] = true if bit == 1 && i == 5 config_hash[:track3_write] = false if bit.zero? && i == 6 config_hash[:track3_write] = true if bit == 1 && i == 6 config_hash[:parity] = true if bit == 1 && i == 7 end config_hash rescue StandardError => e raise e end |
.help ⇒ Object
Display Usage for this Module
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 |
# File 'lib/pwn/plugins/msr206.rb', line 1165 public_class_method def self.help puts "USAGE: msr206_obj = #{self}.connect( block_dev: 'optional serial block device path (defaults to /dev/ttyUSB0)', baud: 'optional (defaults to 9600)', data_bits: 'optional (defaults to 8)', stop_bits: 'optional (defaults to 1)', parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none),' flow_control: 'optional - :none|:hard|:soft (defaults to :none)' ) cmds = #{self}.list_cmds parsed_cmd_resp_arr = #{self}.exec( msr206_obj: 'required msr206_obj returned from #connect method', cmd: 'required - cmd returned from #list_cmds method', params: 'optional - parameters for specific command returned from #list_params method' ) #{self}.disconnect( msr206_obj: 'required msr206_obj returned from #connect method' ) #{self}.authors " end |
.list_cmds ⇒ Object
- Supported Method Parameters
-
cmds = PWN::Plugins::MSR206.list_cmds
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/pwn/plugins/msr206.rb', line 34 public_class_method def self.list_cmds # Returns an Array of Symbols cmds = %i[ proto_usi0 proto_usi1 version_report simulate_power_cycle_warm_reset configuration_request reproduce_last_command resume_transmission_to_host pause_transmission_to_host abort_command red_on red_off red_flash green_on green_off green_flash yellow_on yellow_off yellow_flash arm_to_read arm_to_read_w_speed_prompts tx_iso_std_data_track1 tx_iso_std_data_track2 tx_iso_std_data_track3 alt_tx_iso_std_data_track1 alt_tx_iso_std_data_track2 alt_tx_iso_std_data_track3 tx_error_data tx_custom_data_forward_track1 tx_custom_data_forward_track2 tx_custom_data_forward_track3 tx_passbook_data alt_tx_passbook_data write_verify card_edge_detect load_iso_std_data_for_writing_track1 load_iso_std_data_for_writing_track2 load_iso_std_data_for_writing_track3 alt_load_iso_std_data_for_writing_track1 alt_load_iso_std_data_for_writing_track2 alt_load_iso_std_data_for_writing_track3 load_passbook_data_for_writing load_custom_data_for_writing_track1 load_custom_data_for_writing_track2 load_custom_data_for_writing_track3 set_write_density set_write_density_210_bpi_tracks13 set_write_density_75_bpi_tracks13 set_write_density_210_bpi_tracks2 set_write_density_75_bpi_tracks2 set_default_write_current view_default_write_current set_temp_write_current view_temp_write_current arm_to_write_with_raw arm_to_write_no_raw arm_to_write_with_raw_speed_prompts ] rescue StandardError => e raise e end |
.load_card_from_file(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.load_card_from_file(
msr206_obj: 'required - msr206_obj returned from #connect method'
)
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 |
# File 'lib/pwn/plugins/msr206.rb', line 1036 public_class_method def self.load_card_from_file(opts = {}) msr206_obj = opts[:msr206_obj] file = '' restore_msg = '' loop do if restore_msg.empty? exec_resp = exec( msr206_obj: msr206_obj, cmd: :green_flash ) end print 'Enter File Name to Restore to Card: ' file = gets.scrub.chomp.strip break if File.exist?(file) restore_msg = "\n****** ERROR: #{file} does not exist ******" puts restore_msg exec_resp = exec( msr206_obj: msr206_obj, cmd: :green_off ) exec_resp = exec( msr206_obj: msr206_obj, cmd: :yellow_flash ) end # Read Card from Backup track_data = JSON.parse( File.read(file), symbolize_names: true ) exec_resp = exec( msr206_obj: msr206_obj, cmd: :yellow_off ) encoding = track_data.first[:encoding] if track_data.length == 3 write_card( msr206_obj: msr206_obj, encoding: encoding, track_data: track_data ) rescue StandardError => e raise e end |
.read_card(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.read_card(
msr206_obj: 'required - msr206_obj returned from #connect method'
)
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 |
# File 'lib/pwn/plugins/msr206.rb', line 844 public_class_method def self.read_card(opts = {}) msr206_obj = opts[:msr206_obj] type = opts[:type].to_s.scrub.strip.chomp.to_sym encoding = :waiting_for_selection loop do puts "\nENCODING OPTIONS:" puts '[(I)SO Standard]' puts '[(A)LT ISO Standard]' puts '[(R)aw]' print 'ENCODING TYPE >>> ' encoding_choice = gets.scrub.chomp.strip.upcase.to_sym case encoding_choice when :I encoding = :iso break when :A encoding = :iso_alt break when :R encoding = :raw break end end wait_for_swipe( msr206_obj: msr206_obj, type: :arm_to_read, encoding: encoding ) rescue StandardError => e raise e end |
.write_card(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::MSR206.write_card(
msr206_obj: 'required - msr206_obj returned from #connect method', encoding: 'required - :iso || :alt_iso || :raw', track_data: 'requred - track data to write (see #backup_card for structure)'
)
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 |
# File 'lib/pwn/plugins/msr206.rb', line 940 public_class_method def self.write_card(opts = {}) msr206_obj = opts[:msr206_obj] encoding = opts[:encoding].to_s.scrub.strip.chomp.to_sym track_data = opts[:track_data] puts 'IN ORDER TO GET BLANK TRACKS, A STRONG MAGNETIC FIELD MUST BE PRESENT TO FIRST WIPE THE CARD TARGETED FOR WRITING.' # puts 'Default Write Current:' # exec_resp = exec( # msr206_obj: msr206_obj, # cmd: :view_default_write_current # ) # puts exec_resp.inspect # puts 'Temporary Write Current:' # exec_resp = exec( # msr206_obj: msr206_obj, # cmd: :view_temp_write_current # ) # puts exec_resp.inspect coercivity = :waiting_for_selection loop do puts "\nCOERCIVITY OPTIONS:" puts '[(H)igh (Most Often Black Stripe)]' puts '[(L)ow (Most Often Brown Stripe)]' print 'COERCIVITY LEVEL >>> ' coercivity_choice = gets.scrub.chomp.strip.upcase.to_sym # Write Current Settings vs. Media Coercivties # Media Coercivity (Oersteds)|Write Current Setting*|Typical Usage # 300 |36 |Low coercivity # 600 | | # 1800 | | # 3600+ |255 |Typical high corcivity case coercivity_choice when :H coercivity = [0x32, 0x35, 0x35] break when :L coercivity = [0x30, 0x33, 0x36] break end end exec_resp = exec( msr206_obj: msr206_obj, cmd: :set_temp_write_current, params: coercivity ) track_data = wait_for_swipe( msr206_obj: msr206_obj, type: :arm_to_write_no_raw, encoding: encoding, track_data: track_data ) exec_resp = PWN::Plugins::MSR206.exec( msr206_obj: msr206_obj, cmd: :simulate_power_cycle_warm_reset ) track_data rescue StandardError => e raise e end |