I have done this myself. The algorithm uses DFS. And on every step it goes 4 levels and finds if the found vertex is the same as the one for which is done the step. In formal language it should be something like this:
for path in dfs(start=node, max_depth=4):
if len(path) == 4 and path[1] == path[4]:
output.append(path)