Most education systems, (such as moodle) will have this sort of functionality built in to the educators side of the interface.
It works great for word type submissions but for code it is a bit more difficult as code chunks are pretty similar in operation and structure and you will see multiple hits on each chunk.
This is because coding is often more about functionality rather than authoring and getting chunks from the net is a standard practise when learning/teaching.
As Markus identified the MOSS tool is closer to the type of tool you are looking for but even in its own What is Moss Not? section of their documentation it identifies the issues with using a tool in isolation.
Moss is not a system for completely automatically detecting
plagiarism. Plagiarism is a statement that someone copied code
deliberately without attribution, and while Moss automatically detects
program similarity, it has no way of knowing why codes are similar. It
is still up to a human to go and look at the parts of the code that
Moss highlights and make a decision about whether there is plagiarism
At uni we were encouraged to seek to out pre-existing code to incorporate as long as the chunk was identified and attributed to the author, (we had to have the links to the chunks detailed within our comments), there was also a percentage of attributed chunks that we could use, (i think it was something around 35%).
The real trick was in the student explaining why each chuck worked and how it could be minimised or improved to better suit the desired outcome.
Checking if code has just been copy pasted between students was more of an issue, but you will find those sort of issues are pretty easy to spot because you will see the exact same layout, structure and even the same naming of functions and variables.
Often the best way to check is to have the students add detailed comments to each chunk as these are often more personal as most students have vernacular or cadence that is more apparent.
This coupled with peer reviews and assessment is the best way to identify plagiarism in coding.
Not the best answer for you but hopefully it works out for your situation.