Designing a self Recallable/Destructible email program - security

This is one of my assignments and I need some help in getting started. The basic idea behind the assignment is that I have to design a self destructible email program that is capable of destructing the message after (n) time duration.
Speaking about self destructible emails, there are quite a few ones on the internet offering the same service. But what they do is, they just convert the email message into an image and store them on their servers. Now, they send the message attaching the image inline with it. After they receive a hit on that image (which means that the message was being opened), they simply delete the image and the inline image link breaks! BOOM!
IMO, that's not what a self destructing email should be like. Nevertheless, in my case, I have to take care of following points:
I have to do it for TEXT. No image, nothing else.
I have to assume that the systems used throughout the process will be UNIX based (I don't know how that is going to make a difference).
There are also some hints regarding the usage of various network layers in solving the problem.
This isn't supposed to be done "in general". What I mean by that is, I have to do that ONLY for one/two UNIX systems. Let me put it this way, all I have is two UNIX systems and nothing else. Now I want to create a program (in UNIX itself) that would do that self-destructing thing. I have total control of protocols and the network layers and I have to code anything and everything required at any level.

This is more geared towards the StackOverflow side of things but I have no problem getting you started.
The first thing I'd like to point out is that you seem to be heavily over-analyzing this. The services that have self-destructing e-mails which are image based are simply deleting a file after it is viewed. All you need to do differently is put that text in a file and get it's contents before deleting it. This fits well with the UNIX philosophy since so many programs already make use of flat files.
The part you seem to have left out is how you are building this. You describe it as an e-mail program and then talk about web services. Is this a web-based project or a program you are designing for Linux? Do you have to code everything from scratch or can you parse output from Linux utilities to grab the mail? These kinds of things really would simplify the process.

Related

Fatal Python error: (pygame parachute) Segmentation Fault Error [duplicate]

I need to do some basic networking for a Pygame project.
Basically, it's a 2D single player or cooperative game. The networking only needs to support two players, with one as a host.
The only information that needs to be sent is the positions of players, creeps and bullets.
I've been reading around and Twisted keeps coming up, but I haven't done networking before, and I'm not sure if that might be an overkill.
So, is it possible for a relative newbie to implement networking in Pygame?
This was asked recently on Reddit, so I'll more or less just copy my answer over from there. I apologize for not being able to provide more links, I have <10 rep so I can only post two at a time.
Twisted might work, but I don't have a whole lot of experience with it. I'd recommend going with sockets, as that's what Twisted uses in the background anyway. Beej's guide (google it) is pretty much the Holy Bible of sockets if you want to learn how they work (in C++, but the concepts extend everywhere). Python does abstract some of the complexity away, but it's still a good idea to know what's going on in the background.
For Python specific sockets, you can go ahead and just use the howto (user745294 posted a link above). Here's a nice article titled "What every programmer needs to know about Game Networking". It goes into the different types of major networking styles (client-server, p2p, udp v. tcp, etc.) and the history behind what some major games used for their networking.
Below is a link to a demo I did on making a networked "game" in Python 2.6/Pygame. It's not actually a game, but each client you create connects to the server and controls a character. You can move your character with the arrow keys and the character will move on all connected clients. I tried commenting the source code with some indication of what I'm sending back and forth, but you may need a little knowledge about sockets to understand it.
The source code is provided in the codepad links in the comment below this post. You will need to provide two images in the same directory as the scripts:
bg.png is the background sprite. It should be an image 400px wide and 300px tall (this can be changed in the GameClient class if needed)
sprite.png is the player character. It should be smaller than the background so that you can see it moving around.
You can use Twisted for networking with Pygame. The "game" project on Launchpad has some examples of how one might integrate the main loops together; basically, use twisted.internet.task.LoopingCall to draw Pygame frames and handle input, while letting the Twisted reactor of your choice run normally.
Since you are already using Pygame, I think this light networking library made for Pygame will do what you need and teach you, but not overwhelm you.
"Mastermind Networking Lib" via pygame.org
There is Pyro (Python remote objects) as another solution for networking in Python.
http://irmen.home.xs4all.nl/pyro/
Using raw sockets is low-level and full of danger. As said before, Twisted is complex and takes to time get up and running. To save yourself some headaches I'd try something like zerorpc.
You need the following solutions:
discovering other player(s) on the (local) network, you don't want player to enter some IP address
handle network errors
serialize messages containing your data (positions, player name, etc.)
handle threading as networking is asynchronous I/O
Above should still be called 'basic', you should really use some fancy networking library with idiomatic API.
Essentially you need to expose the network service (in its own thread) that will push messages to Python's Queue, and then access this same queue from your Pygame code, and if there is a message then you update whatever structures you use to store player's position and draw it on screen.
You shouldn't send stuff like bullet positions over the network as they can be easily (and faster) calculated locally. You just send an event like bullet_shot over the network with a source position and velocity vector.

WebRTC/getUserMedia - Getting source of stream

I have searched far and wide for the answer to this and am surprised that there aren't more people talking about this.
There doesn't appear to be a way to ensure that the stream/track that is selected is a native camera versus a stream provided by something like ManyCam (https://manycam.com/?__c=1) or AlterCam. The use case for this is secure apps that, for security reasons, want to ensure that the video/images/data coming through the stream comes from a "legitimate" (native camera) source rather than a source that can really be anything and/or altered before it gets to the client code.
Is there any known way of ensuring this? I'm not looking for a whitelist/blacklist option, since many of the camera programs allow changing of the camera name, which ends up showing up in the label property.

How to format the terminal window node is using to be in sections

I'm wanting to make an application with node have a cli interface, as it needs to be ran in a terminal. I want to split the terminal into several sections, one with some identification as to who is viewing the application, another with some other random info, a menu on the side that you can use the arrow keys to move up and down the options, a main logs section, and another that you can type, and press enter to send text in. I've drawn up a little diagram of how I want to make it: (I know this looks awful, it was made in mspaint)
I've gotten the console input part working by using the readline module, but I don't even know where to really start with designing the terminal how I want it, setting text in certain sections, etc. I've looked around at things like terminal-kit, and clci, but either they didn't seem like what I wanted, or their docs/examples were a mess.
I would prefer to do this with node only, not using another application in another language, as all of the stuff going to the console sections will be from the same node application.
I found the blessed library at https://github.com/chjj/blessed. It is based on the ncurses library (written in C, https://en.wikipedia.org/wiki/Ncurses) and it allows you to create different sections with specified heights, widths, etc. in different areas of the terminal. Very useful in theory, and you can follow the advice on the github page, clone the repo into your desktop, look into the test folder, and then run the different files ie. node test/widget-form.js to see the different types of interfaces that you can create in your terminal.
It hasn't really worked for me, because it keeps crashing on my end, but I see that there are a lot of open pull requests and that people are still trying, so it might be working for some, although I think that the usage for some "widgets" is limited. The next best thing I can recommend is either blessed-contrib or neo-blessed, the former being developed by some dude from Facebook. Blessed-contrib is newer so you might have more luck with it, but it's essentially made for visual output, so you'd be able to create a section for a log, a selection menu, a paragraph section, etc. but nothing to create an area where you can input text (so 4/5 of what you need), based on my reading of the documentation, which you'll find here https://github.com/yaronn/blessed-contrib.
I personally think it's dope. Good luck with it, I'm going through the motions of understanding the documentation better myself, and I've delved pretty deeply in it, so feel free to reach out if you need any help.
On another note, let me know if you've found anything else other than the resources I mentioned, which would be very helpful for me, as the alternative right now is for me to code the text user interface myself using C and the ncurses library, which I'm trying to avoid if it's unnecessary :)
EDIT:
I found something for you and for me that might send us in the right direction. Good news. This is the gitter-cli. It uses the library I mentioned above blessed. If you clone the gitter-cli's repo, follow the instructions to get a token and create an account, and join one of the rooms (you can find the name of the rooms like 'gitterHQ/javascript' on the gitter.im website), you'll see that the chat works. There might be some optimizations I'm not aware of, but I recommend just delving into their code while also delving into the blessed documentation to understand how it works. It should give you an idea of what to do next.
It took me a lot of hours to find all these different resources and connect the dots so you should definitely check them out.

Recording Line Numbers of Executed Paths

For Google Chrome Extension, is it possible to record the sequence of line numbers (with file names) (with the existing variables values in case of JavaScript) that are executed during the execution of HTML/CSS/JavaScript?
This is certainly possible but exceedingly difficult.
One can, in principle, implement it using chrome.debugger API, which gives the same access to the page as DevTools.
However, that API basically consists of sending almost-raw Remote Debugging protocol commands, and there aren't many samples to go on with. Debugger domain seems relevant.
So, it's possible but it's a lot of work, and additionally it's going to slow execution to a crawl.
As such, this is not a good problem to solve with extensions. It's better served by modification of Chromium code and maybe existing debugging capabilities of it. Basically, to efficiently output this information you need to get down to browser internals.

online trading bot

I want to code a trading bot for Magic: The Gathering Online. This bot should wait until someone offers to trade, accept, look through the cards available from the other trader (the information is shown on screen), and perform other similar functions. I have several questions:
How can it know that someone is offering a trade?
How can it know that the other trader has some card (the informaion is stored in pictures)?
I just cannot imagine right now how to do it, I have no experience with it, until now I've been coding only console programs for my physics neсessities.
First, you should note that some online games forbid bots, as they can give certain players unfair advantages. The MTGO Terms of Service do not seem to say anything about this, though they do put restrictions on anything that might negatively impact the service. They have also said that there is a possibility they will add an API in the future, so they don't seem to be against the idea of automation, but are not supporting it at the moment. Tread carefully here, but it looks like it should be OK to write a bot as long as it is not harmful or abusive. This is not legal advice, and it would be a good idea to ask the folks who run MTGO for permission. edit since I wrote this, it has been pointed out that there are lots of bots already, so there should be no problems writing bots.
Assuming that it is not forbidden by the terms of service, but they do not have an API, you will have to find a way to detect what's going on, and control the game automatically. There's a pretty good series of articles on writing poker bots (archived copy), which has some good information on how to inject a DLL into an application, scrape the screen, and control the application. That might provide you with a starting point for doing this sort of thing.
You might also want to look for tools that other people have already written for doing this. It looks like there are several existing MTGO bots, but they all seem a bit sketchy (there have been some reports of them stealing passwords), so be careful there.
Edit
Since this answer still seems to be getting upvotes, I should probably update it with some more useful information. Since writing this, I have found a great UI automation system called Sikuli. It allows you to write programs in Python that automate a GUI. It includes image recognition features which make it very easy to recognize buttons, cards, and other UI elements; you just take a screenshot, crop it down to include just the thing you're interested in, and do fuzzy image matching (so that changing backgrounds and the like doesn't cause the match to fail). It even includes a custom IDE that allows you to embed those screenshots directly in your source code, so you can see exactly what the code is looking for. Here's an example from the documentation (apologies for the code formatting, doing images inline in code is not easy given StackOverflow's restricted subset of HTML):
def resizeApp(app, dx, dy):
switchApp(app)
corner = find(Pattern().targetOffset(3,14))
drop_point = corner.getTarget().offset(dx, dy)
dragDrop(corner, drop_point)
resizeApp("Safari", 50, 50)
This is much easier to get started with than the techniques mentioned in the article linked above, of injecting a DLL into the process you are debugging. Sikuli runs entirely at the UI level, so you never have to modify the program you are automating or worry about changes to the internals breaking your script.
One thing it is a bit poor at is handling text; it has OCR features, but they aren't all that good. If the text is selectable, however, you can select the text, copy it, and then look directly at the clipboard.
If I were to write a bot to automate something without a good API or text-based interface, Sikuli is probably the first tool I would reach for.
This answer is constructed from my comments.
What you are trying to do is hard, any way you try and do it.
Arguably the easiest way to do it is to totally mimic the user. So the application presses buttons, moves the mouse etc. The downside with this is that it is dependant on being able to recognise the screen.
This is easier if you can alter the games files as you can then just skin ( changing the image (texture)) the required cards to a single unique colour.
The major down side is you have to have the game as the top level window or have the game running in a virtual machine. Neither of which is ideal.
Another method is to read the processes memory. You may be able to find a list of memory locations, which would make things simpler, otherwise it involves a lot of hardwork, a debugger to deduce the memory addresses. It also helps (a lot) to be able to understand assembly.
The third method is to intercept the packets, and alter them. This is easier that the method above as it (at least for me) is easier to reverse engine the protocol as you have less information to deal with. It is just a matter of setting up a packet sniffer and preforming a action with one variable different (for example, the card) and comparing the differences.
The thing you need to check are that you are not breaking the EULA. I don't know how the game works, but most of the games I have come across have a EULA that prohibits (i.e. You get banned) doing any of the things I have mentioned.

Resources