How can I find out if my iOS device has been jailbroken (with a drive-by exploit for example)?
Is there an app for that?
It can be difficult it if was done stealthily (for example - it's fairly easy to hide things like Cydia) - my approach would be to see if iBooks or Skype work - iBooks has historically been broken by jailbreaks and Skype is designed to prevent use on a jailbroken device (which is annoying if you want to use skype, but excellent if you want to know if you are on a jailbroken device).
Basically, if you can execute arbitrary code or write to arbitrary disk locations, you're jailbroken.
iOS security researcher Stefan Esser (also knows as i0n1c) has developed an application called System and Security Info to determine if an iOS device is currently jailbroken by testing for the abilities that you gain from jailbreaking.
Update: Apple has taken down System and Security Info.
A jailbreak is essentially 3 points:
To check for the presence of AFC2 it is sufficient to use a dedicated PC app such as iFunBox while checking for SSH is harder due to the ability for a dedicated individual (or software!) to change the listening port from the standard 22. And this 3rd point isn't even formally required to call it a jailbreak.
You can check for the 2nd point by checking the /etc/fstab file, and since having access to the root partition would easily demonstrate being jailbroken the only alternative would be a SSH ramdisk.
If you're really paranoid about it and don't care for some potentially wasted space if your device was indeed jailbroken, you can create a local backup via iTunes and restore the OS followed by the backup.