Whom to ask to write a reference? I earned my Bs.C. in Computer Science five years ago. Two years ago I started taking courses of advanced level from Computer Science department. Now I am thinking about applying to M.Sc. studies abroad.

The usual requirement is to submit three references. The problem is I don't have someone to write a reference. I wasn't very successful in these advanced courses, therefore I don't think I could ask a lecturer to write a reference, nor his assistant who was checking homework assignments. As option, I could find a professor and start working with him for a while; I am not sure that the result of this work will be a paper, but at least he will be able to somehow evaluate my ability to do a research, the problem is I need three of them. 

In addition, I am not sure I could ask someone from my B.Sc. studies to write a reference, just because I lost touch with them.

In your opinion, what is the best way to get three references?
I would reach out to the instructors of the classes you enjoyed the most and put a good effort into, regardless of grade. 

As an instructor myself, I have written recommendations for students who have and who haven't received straight A's - my main requirement for writing a recommendation is can I see this person succeeding in the position I am recommending them for? If not, I let the student know that I am not the right person to write the recommendation for them.

I say reach out to your instructors - the worst they are going to tell you is no.