All Projects → crocs-muni → APDUPlay

crocs-muni / APDUPlay

Licence: other
PC/SC inspection and manipulation tool

Programming Languages

C++
36643 projects - #6 most used programming language
java
68154 projects - #9 most used programming language
c
50402 projects - #5 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to APDUPlay

apdu-intercept
Smartcard APDU interception and MITM for one smartcard model
Stars: ✭ 33 (-19.51%)
Mutual labels:  smartcard, apdu
oseid
Microchip AVR based smartcard/token with ECC and RSA cryptography
Stars: ✭ 17 (-58.54%)
Mutual labels:  smartcard, apdu
esteid.js
APDU interface of EstEID cards in JavaScript
Stars: ✭ 14 (-65.85%)
Mutual labels:  apdu, pcsc
JCAlgTest
Automated testing tool for algorithms from JavaCard API supported by particular smart card. Performance testing of almost all available methods. The results for more than 100+ cards.
Stars: ✭ 82 (+100%)
Mutual labels:  smartcard
Yubikey Agent
yubikey-agent is a seamless ssh-agent for YubiKeys.
Stars: ✭ 1,744 (+4153.66%)
Mutual labels:  smartcard
win-gpg-agent
[DEPRECATED] Windows helpers for GnuPG tools suite
Stars: ✭ 214 (+421.95%)
Mutual labels:  smartcard
fortify
Fortify enables web applications to use smart cards, local certificate stores and do certificate enrollment. This is the desktop application repository.
Stars: ✭ 88 (+114.63%)
Mutual labels:  smartcard
scd-pkcs11
PKCS#11 provider with smart card support via GnuPG
Stars: ✭ 35 (-14.63%)
Mutual labels:  smartcard
tls-ca-manage
Multi-level Certificate Authority Management tool, front-end tool to OpenSSL, written in bash shell.
Stars: ✭ 19 (-53.66%)
Mutual labels:  smartcard
hsmwiz
HSMWiz is a frontend for OpenSC, pkcs11tool and pkcs15tool to ease handling of HSM smartcards
Stars: ✭ 27 (-34.15%)
Mutual labels:  smartcard
cie-middleware-linux
Middleware della CIE (Carta di Identità Elettronica) per Linux
Stars: ✭ 31 (-24.39%)
Mutual labels:  smartcard
Opensc
Open source smart card tools and middleware. PKCS#11/MiniDriver/Tokend
Stars: ✭ 1,792 (+4270.73%)
Mutual labels:  smartcard
apdu-over-ble
Specification of a protocol to transmit APDU commands and responses over Bluetooth Low Energy
Stars: ✭ 17 (-58.54%)
Mutual labels:  apdu
Yubikey Guide
Guide to using YubiKey for GPG and SSH
Stars: ✭ 6,709 (+16263.41%)
Mutual labels:  smartcard
simtrace2
Osmocom SIM card tracer, v2.0; mirror of https://gitea.osmocom.org/sim-card/simtrace2
Stars: ✭ 54 (+31.71%)
Mutual labels:  smartcard
ccid-utils
A USB smartcard driver including GSM SIM and EMV credit/debit card development platforms
Stars: ✭ 37 (-9.76%)
Mutual labels:  smartcard
cie-middleware
Middleware della CIE (Carta di identità elettronica)
Stars: ✭ 57 (+39.02%)
Mutual labels:  smartcard
cie-cns-apache-docker
L'obiettivo di questo progetto è quello di fornire un template pronto all'uso che realizza un sistema di autenticazione tramite la Smart Card TS-CNS (o CNS) e la CIE (Carta d'Identità Elettronica) basato su Apache HTTP. Ognuno può poi modificare o specializzare questo progetto sulla base delle proprie esigenze Si tratta di un progetto docker per…
Stars: ✭ 48 (+17.07%)
Mutual labels:  smartcard
Pkcs11Interop.X509Store
Easy to use PKCS#11 based X.509 certificate store
Stars: ✭ 24 (-41.46%)
Mutual labels:  smartcard
jfreesteel
A native Java library, a Swing GUI application and an applet to read the Serbian eID card, built on javax.smartcardio
Stars: ✭ 48 (+17.07%)
Mutual labels:  smartcard

PC/SC APDU inspection and manipulation tool (APDUPlay)

Latest release

Windows DLL: Build status Linux SO: Build Status

The APDUPlay project allows you to log, modify, redirect and visualize smartcard communication realized via PC/SC interface (winscard.dll library). The functionality is achieved by custom "stub" library (provided by APDUPlay) which intercepts and redirects the communication to original winscard.dll (provided by Microsoft) or remote socket proxy. The project supports applications running on Windows Vista, 7, 8, 10 and Linux both 32- and 64-bit.

The primary uses for APDUPlay project are debugging and reverse engineering of unknown APDU-based protocols, redirection of communication to the remote smartcard and penetration testing of black-box applications. The APDUPlay project is based on (now inactive) ApduView tool by Andrew Fernandes which allowed to log PC/SC communication.

The APDUPlay project provides the following functionality:

  • Log content and additional information about the exchanged PC/SC communication (APDU packets).
  • Redirect communication via socket to other device/computer to support remotely connected smartcards (only Windows version at the moment).
  • Manipulate the communication in real time based on pattern matching rules (e.g., always return success for VERIFY PIN command despite an incorrect PIN value).
  • Reorder list of smart card readers detected and returned by SCardListReaders (e.g., if multiple readers exist and application always connects only to the first one)
  • Visualize captured data in a structured way (separate Java project Parser combined with Graphviz).

See more details at https://github.com/crocs-muni/APDUPlay/wiki.

Installation (Windows OS)

  1. Find out if a targeted application is 32- or 64-bit (Use Microsoft Sysinternals Sigcheck utility). Run sigcheck.exe targetApp.exe and look for MachineType: 32-bit or 64-bit (also works for dll files)
  2. Copy Winscard.dll from your system folder (c:\Windows\System32\winscard.dll for 64-bit target application (if you are running 64-bit OS) or c:\Windows\SysWOW64\winscard.dll for 32-bit application) to the folder with target application and rename it to original32.dll or original64.dll respectively. NOTE: c:\Windows\System32\ contains either 32-bit or 64-bit version based on your OS.
  3. Copy Winscard.dll from APDUPlay project to the folder with target application (the folder should contain winscard.dll binary from APDUPlay project AND originalXX.dll which is Microsoft's original winscard.dll)
  4. Run the application and inspect resulting files winscard_log.txt and winscard_rules_log.txt
  5. (Optional) Change configuration file winscard_rules.txt to modify default behavior (see examples below)

1. Logging of exchanged APDU commands

This simplest use case allows you to log all APDUs exchanged between a target application and a physical smartcard.

target_application <--> APDUPlay_winscard.dll <--> original64.dll <--> smartcard
                         |                                  ^
                         v                                  | 
                   winscard_log.txt (logged APDUs)     renamed winscard.dll by Microsoft
  1. Find out if your application requires 32- or 64-bit winscard.dll (e.g., using Sigcheck utility)
  2. Copy Microsoft's original winscard.dll library to a target application folder and rename it to original32.dll or original64.dll (based on the Step 1).
  3. Place APDUPlay's custom winscard.dll library to a target application folder, so it is loaded first.
  4. Place configuration file named winscard_rules.txt into the same folder. Read full documentation of winscard_rules.txt file.

The target application folder should now look like this (CAProfiler_64b.exe used as an example)

.
..
CAProfiler_64b.exe       <---- target application (64-bit)
original64.dll           <---- original Microsoft's winscard.dll copied from C:\System\System32\
Winscard.dll             <---- APDUPlay's stub winscard.dll (64-bit)
winscard_rules.txt       <---- configuration file loaded by APDUPlay's stub winscard.dll

The simple example content of winscard_rules.txt file should look like:

[WINSCARD]
LOG_EXCHANGED_APDU = 1
LOG_BASE_PATH = ./
  1. Now run target application (CAProfiler_64b.exe in this example). The application should execute normally.
>CAProfiler_64b.exe
Available readers:
1. Generic EMV Smartcard Reader 0
2. Simona /111.222.123.033@07
... 
The following applets were detected:
APPLET_AID_JCOP_CM             : a0 00 00 00 03 00 00 00
APPLET_AID_VISA_PREFIX         : a0 00 00 00 03
  1. Inspect the generated files with an intercepted communication (winscard_log.txt, apduplay_debug.txt ...).
[begin]
SCardTransmit (handle 0x00000000)#
apduCounter:0#
totalBytesINCounter:1#
transmitted:00 a4 04 00 05 a0 00 00 00 03 00
responseTime:12#
SCardTransmit result:0x0#
received:6f 10 84 08 a0 00 00 00 03 00 00 00 a5 04 9f 65 01 ff 90 00

SCardTransmit (handle 0x00000000)#
apduCounter:1#
totalBytesINCounter:12#
transmitted:00 a4 04 00 05 a0 00 00 00 04 00
responseTime:9#
SCardTransmit result:0x0#
received:6a 82
...
  1. (Optional) Inspect other APDUPlay features like APDU commands modification or redirection to remote socket proxy.

The installation and usage process is relatively simple, but may be little tricky if something does not work (e.g., the library is loaded from a different than an expected path, the application terminates without giving any error message, etc.). The first step is always to make sure that APDUPlay's stub library is used together with the correct winscard_rules.txt. See Examples section for detailed step-by-step installation and troubleshooting.

Note: This example shows the simplest use case only with logging of the exchanged APDU commands. For more advanced examples check wiki pages for examples.

2. Redirection of APDU commands to socket proxy (on a remote computer)

This use case allows you to utilize APDUPlay to redirect all APDU commands to specified socket proxy and propagate back the proxy response as response APDU command back to target application. The proxy can run on localhost or remote computer and can be written in any language.

There are two primary uses for this feature:

  1. A simulation of locally-connected smartcard while connected to a remote computer.
target_application <--> APDUPlay_winscard.dll <--> socket_proxy_localhost

target_application <--> APDUPlay_winscard.dll <--> socket_proxy_remotehost <--> smartcard_remotehost
  1. More advanced processing of the exchanged APDUs in any suitable programming language and without need for recompilation of APDUPlay dll/so libraries. The proxy can be written in any language (e.g., Python pySimonaProxy).
target_application <--> APDUPlay_winscard.dll <--> python_socket_proxy_localhost

target_application <--> APDUPlay_winscard.dll <--> socket_proxy_localhost <--> RESTproxy_remotehost <--> smartcard_remotehost

Note, that original winscard.dll (renamed as original64.dll) is not even used for transmission of APDU in this case as no physical smartcard is contacted/present on localhost.

Redirection to smartcard connected to remote computer

TODO

Multiple smartcards connected to remote computer

TODO

3. Manipulate exchanged APDUs in real time based on pattern matching rules

This use case allows to match exchanged APDU (both input and response) against the defined patterns and modify it accordingly before sending to physical smartcard (input APDU) or back to the target application (response APDU).

target_application <--> APDUPlay_winscard.dll <--> modified_apdu <--> original64.dll <--> smartcard
                                 ^
                                 |
                           winscard_rules.txt (definition of rewrite rules)
[WINSCARD]
...
MODIFY_APDU_BY_RULES = 1                           <---- enable modification of the exchanged APDUs
...
[RULE1]                                            <---- first modification rule 
APDUIN = 1                                         <---- if 1, rule is checked for an input APDU (application to card), if 0 then on response APDU (smartcard to application)
MATCH1=in=1,cla=80,ins=ca,p1=9f,p2=17,data0=90 00  <---- apply rule when input APDU has CLA==0x80, INS==0xca ...
ACTION=in=1,cla=80,ins=cb,p1=9f,p2=17,data0=97 00  <---- if match, then change INS to 0xca and data[0] to 0x97 
USAGE = 1                                          <---- if 1, rule is in use. If 0, then rule is ignored  
[RULE2]                                            <---- another modification rule
...

Examples

The localization of correct winscard.dll path can sometimes be a tedious task, especially for applications using additional frameworks to access PC/SC interface. Check wiki pages for examples with the increasing difficulty:

  1. Simple application directly using winscard.dll (CAProfiler.exe)
  2. Application with persistent agent (gpg2.exe --card-edit)
  3. Java-based application accessing smartcards via JRE: (GlobalPlatformPro gp -l)

Alternatively, you may replace winscard.dll directly inside the system folder. Warning: PC/SC communication from ALL applications running on your system is now intercepted and logged to file including your PINs, passwords etc. - so use this option with care!

Troubleshooting

Please read Troubleshooting wiki page

Related projects

  • APDUTrace - logging via inserted kernel filter driver, works on WinXP-Win10 both 32b and 64b. If you need only the logging on Windows machine, grab this one!
  • APDU spying tool - Windows logging via replacement of wiscard.dll (same approach as APDUPlay), no modification. 64b version only on request.

Bugs and issues

Please, open an issue in case of any bug is found.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].